Set up localization
This commit is contained in:
parent
c9aee4ae20
commit
3fa8c69a49
8 changed files with 106 additions and 3 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,4 +1,5 @@
|
||||||
gems
|
gems
|
||||||
|
locale
|
||||||
*.swp
|
*.swp
|
||||||
db/*.sqlite3
|
db/*.sqlite3
|
||||||
db/*.sqlite3-*
|
db/*.sqlite3-*
|
||||||
|
|
|
||||||
1
Gemfile
1
Gemfile
|
|
@ -7,3 +7,4 @@ gem 'rackup'
|
||||||
gem 'puma'
|
gem 'puma'
|
||||||
gem 'sqlite3'
|
gem 'sqlite3'
|
||||||
gem 'bcrypt'
|
gem 'bcrypt'
|
||||||
|
gem 'gettext'
|
||||||
|
|
|
||||||
16
Gemfile.lock
16
Gemfile.lock
|
|
@ -26,16 +26,29 @@ GEM
|
||||||
concurrent-ruby (1.3.5)
|
concurrent-ruby (1.3.5)
|
||||||
connection_pool (2.5.0)
|
connection_pool (2.5.0)
|
||||||
drb (2.2.1)
|
drb (2.2.1)
|
||||||
|
erubi (1.13.1)
|
||||||
|
forwardable (1.3.3)
|
||||||
|
gettext (3.5.1)
|
||||||
|
erubi
|
||||||
|
locale (>= 2.0.5)
|
||||||
|
prime
|
||||||
|
racc
|
||||||
|
text (>= 1.3.0)
|
||||||
i18n (1.14.7)
|
i18n (1.14.7)
|
||||||
concurrent-ruby (~> 1.0)
|
concurrent-ruby (~> 1.0)
|
||||||
|
locale (2.1.4)
|
||||||
logger (1.6.6)
|
logger (1.6.6)
|
||||||
mini_portile2 (2.8.8)
|
mini_portile2 (2.8.8)
|
||||||
minitest (5.25.5)
|
minitest (5.25.5)
|
||||||
mustermann (3.0.3)
|
mustermann (3.0.3)
|
||||||
ruby2_keywords (~> 0.0.1)
|
ruby2_keywords (~> 0.0.1)
|
||||||
nio4r (2.7.4)
|
nio4r (2.7.4)
|
||||||
|
prime (0.1.3)
|
||||||
|
forwardable
|
||||||
|
singleton
|
||||||
puma (6.6.0)
|
puma (6.6.0)
|
||||||
nio4r (~> 2.0)
|
nio4r (~> 2.0)
|
||||||
|
racc (1.8.1)
|
||||||
rack (3.1.12)
|
rack (3.1.12)
|
||||||
rack-protection (4.1.1)
|
rack-protection (4.1.1)
|
||||||
base64 (>= 0.1.0)
|
base64 (>= 0.1.0)
|
||||||
|
|
@ -59,10 +72,12 @@ GEM
|
||||||
sinatra-activerecord (2.0.28)
|
sinatra-activerecord (2.0.28)
|
||||||
activerecord (>= 4.1)
|
activerecord (>= 4.1)
|
||||||
sinatra (>= 1.0)
|
sinatra (>= 1.0)
|
||||||
|
singleton (0.3.0)
|
||||||
sqlite3 (2.6.0)
|
sqlite3 (2.6.0)
|
||||||
mini_portile2 (~> 2.8.0)
|
mini_portile2 (~> 2.8.0)
|
||||||
sqlite3 (2.6.0-arm64-darwin)
|
sqlite3 (2.6.0-arm64-darwin)
|
||||||
sqlite3 (2.6.0-x86_64-darwin)
|
sqlite3 (2.6.0-x86_64-darwin)
|
||||||
|
text (1.3.1)
|
||||||
tilt (2.6.0)
|
tilt (2.6.0)
|
||||||
timeout (0.4.3)
|
timeout (0.4.3)
|
||||||
tzinfo (2.0.6)
|
tzinfo (2.0.6)
|
||||||
|
|
@ -76,6 +91,7 @@ PLATFORMS
|
||||||
|
|
||||||
DEPENDENCIES
|
DEPENDENCIES
|
||||||
bcrypt
|
bcrypt
|
||||||
|
gettext
|
||||||
puma
|
puma
|
||||||
rackup
|
rackup
|
||||||
rake
|
rake
|
||||||
|
|
|
||||||
18
Rakefile
18
Rakefile
|
|
@ -1,2 +1,20 @@
|
||||||
require_relative 'vote'
|
require_relative 'vote'
|
||||||
require 'sinatra/activerecord/rake'
|
require 'sinatra/activerecord/rake'
|
||||||
|
|
||||||
|
desc "Update PO files"
|
||||||
|
task :updatepo do
|
||||||
|
require 'gettext/tools/xgettext'
|
||||||
|
GetText::Tools::XGetText.run(*["vote.rb"] + Dir.glob("views/*.{rb,erb}") + ["-o", "po/vote.pot"])
|
||||||
|
require "gettext/tools/msgmerge"
|
||||||
|
Dir.glob('po/**/vote.po').collect { |po| /po\/(.+)\/vote\.po/.match(po)[1] }.each do |locale|
|
||||||
|
GetText::Tools::MsgMerge.run("po/#{locale}/vote.po", "po/vote.pot", "-o", "po/#{locale}/vote.po")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
desc "Build MO files"
|
||||||
|
task :buildmo do
|
||||||
|
require 'gettext/tools/msgfmt'
|
||||||
|
Dir.glob('po/**/vote.po').collect { |po| /po\/(.+)\/vote\.po/.match(po)[1] }.each do |locale|
|
||||||
|
GetText::Tools::MsgFmt.run("po/#{locale}/vote.po", "-o", "locale/#{locale}/vote.mo")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
|
||||||
30
po/ca/vote.po
Normal file
30
po/ca/vote.po
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
# SOME DESCRIPTIVE TITLE.
|
||||||
|
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
|
||||||
|
# This file is distributed under the same license as the PACKAGE package.
|
||||||
|
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
|
||||||
|
#
|
||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: PACKAGE VERSION\n"
|
||||||
|
"Report-Msgid-Bugs-To: \n"
|
||||||
|
"POT-Creation-Date: 2025-03-29 21:18-0600\n"
|
||||||
|
"PO-Revision-Date: 2025-03-29 20:41-0600\n"
|
||||||
|
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||||
|
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||||
|
"Language: \n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
|
||||||
|
|
||||||
|
#: ../views/login.erb:1
|
||||||
|
msgid "Login"
|
||||||
|
msgstr "Connexió"
|
||||||
|
|
||||||
|
#: ../views/login.erb:7
|
||||||
|
msgid "Email"
|
||||||
|
msgstr "Correu"
|
||||||
|
|
||||||
|
#: ../views/login.erb:11
|
||||||
|
msgid "Password"
|
||||||
|
msgstr "Contrasenya"
|
||||||
31
po/vote.pot
Normal file
31
po/vote.pot
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
# SOME DESCRIPTIVE TITLE.
|
||||||
|
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
|
||||||
|
# This file is distributed under the same license as the PACKAGE package.
|
||||||
|
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
|
||||||
|
#
|
||||||
|
#, fuzzy
|
||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: PACKAGE VERSION\n"
|
||||||
|
"Report-Msgid-Bugs-To: \n"
|
||||||
|
"POT-Creation-Date: 2025-03-29 21:18-0600\n"
|
||||||
|
"PO-Revision-Date: 2025-03-29 21:18-0600\n"
|
||||||
|
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||||
|
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||||
|
"Language: \n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
|
||||||
|
|
||||||
|
#: ../views/login.erb:1
|
||||||
|
msgid "Login"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: ../views/login.erb:7
|
||||||
|
msgid "Email"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: ../views/login.erb:11
|
||||||
|
msgid "Password"
|
||||||
|
msgstr ""
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
<h1>Log in</h1>
|
<h1><%= _("Login") %></h1>
|
||||||
<% if @error %>
|
<% if @error %>
|
||||||
<p class="error"><%= @error %></p>
|
<p class="error"><%= @error %></p>
|
||||||
<% end %>
|
<% end %>
|
||||||
<form action="/login" method="POST">
|
<form action="/login" method="POST">
|
||||||
<p>
|
<p>
|
||||||
<label for="email">Email</label>
|
<label for="email"><%= _("Email") %></label>
|
||||||
<input type="text" name="email">
|
<input type="text" name="email">
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<label for="password">Password</label>
|
<label for="password"><%= _("Password") %></label>
|
||||||
<input type="password" name="password">
|
<input type="password" name="password">
|
||||||
</p>
|
</p>
|
||||||
<button type="submit">Log in</button>
|
<button type="submit">Log in</button>
|
||||||
|
|
|
||||||
6
vote.rb
6
vote.rb
|
|
@ -1,6 +1,7 @@
|
||||||
require 'sinatra'
|
require 'sinatra'
|
||||||
require 'sinatra/activerecord'
|
require 'sinatra/activerecord'
|
||||||
require 'bcrypt'
|
require 'bcrypt'
|
||||||
|
require 'gettext'
|
||||||
require 'securerandom'
|
require 'securerandom'
|
||||||
require_relative 'mj'
|
require_relative 'mj'
|
||||||
|
|
||||||
|
|
@ -59,6 +60,11 @@ set :values, [ { :id => 1, :label => "Awful" },
|
||||||
{ :id => 7, :label => "Excellent" } ]
|
{ :id => 7, :label => "Excellent" } ]
|
||||||
MajorityJudgment.values = settings.values
|
MajorityJudgment.values = settings.values
|
||||||
|
|
||||||
|
include GetText
|
||||||
|
set_output_charset('UTF-8')
|
||||||
|
bindtextdomain('vote', 'locale')
|
||||||
|
set_locale('ca')
|
||||||
|
|
||||||
get '/' do
|
get '/' do
|
||||||
redirect '/login' unless current_user
|
redirect '/login' unless current_user
|
||||||
@votes = Vote.all
|
@votes = Vote.all
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue