diff --git a/.gitignore b/.gitignore index dcee8fa..3e6f269 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ gems +locale *.swp db/*.sqlite3 db/*.sqlite3-* diff --git a/Gemfile b/Gemfile index 91a092f..1884105 100644 --- a/Gemfile +++ b/Gemfile @@ -7,3 +7,4 @@ gem 'rackup' gem 'puma' gem 'sqlite3' gem 'bcrypt' +gem 'gettext' diff --git a/Gemfile.lock b/Gemfile.lock index c7e98b5..ca3398b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -26,16 +26,29 @@ GEM concurrent-ruby (1.3.5) connection_pool (2.5.0) 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) concurrent-ruby (~> 1.0) + locale (2.1.4) logger (1.6.6) mini_portile2 (2.8.8) minitest (5.25.5) mustermann (3.0.3) ruby2_keywords (~> 0.0.1) nio4r (2.7.4) + prime (0.1.3) + forwardable + singleton puma (6.6.0) nio4r (~> 2.0) + racc (1.8.1) rack (3.1.12) rack-protection (4.1.1) base64 (>= 0.1.0) @@ -59,10 +72,12 @@ GEM sinatra-activerecord (2.0.28) activerecord (>= 4.1) sinatra (>= 1.0) + singleton (0.3.0) sqlite3 (2.6.0) mini_portile2 (~> 2.8.0) sqlite3 (2.6.0-arm64-darwin) sqlite3 (2.6.0-x86_64-darwin) + text (1.3.1) tilt (2.6.0) timeout (0.4.3) tzinfo (2.0.6) @@ -76,6 +91,7 @@ PLATFORMS DEPENDENCIES bcrypt + gettext puma rackup rake diff --git a/Rakefile b/Rakefile index becde0a..ae9277e 100644 --- a/Rakefile +++ b/Rakefile @@ -1,2 +1,20 @@ require_relative 'vote' 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 diff --git a/po/ca/vote.po b/po/ca/vote.po new file mode 100644 index 0000000..cf5df6c --- /dev/null +++ b/po/ca/vote.po @@ -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 , 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 \n" +"Language-Team: LANGUAGE \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" diff --git a/po/vote.pot b/po/vote.pot new file mode 100644 index 0000000..b7088a4 --- /dev/null +++ b/po/vote.pot @@ -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 , 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 \n" +"Language-Team: LANGUAGE \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 "" diff --git a/views/login.erb b/views/login.erb index ebd8a03..2c64001 100644 --- a/views/login.erb +++ b/views/login.erb @@ -1,14 +1,14 @@ -

Log in

+

<%= _("Login") %>

<% if @error %>

<%= @error %>

<% end %>

- +

- +

diff --git a/vote.rb b/vote.rb index 065cfc2..b939829 100644 --- a/vote.rb +++ b/vote.rb @@ -1,6 +1,7 @@ require 'sinatra' require 'sinatra/activerecord' require 'bcrypt' +require 'gettext' require 'securerandom' require_relative 'mj' @@ -59,6 +60,11 @@ set :values, [ { :id => 1, :label => "Awful" }, { :id => 7, :label => "Excellent" } ] MajorityJudgment.values = settings.values +include GetText +set_output_charset('UTF-8') +bindtextdomain('vote', 'locale') +set_locale('ca') + get '/' do redirect '/login' unless current_user @votes = Vote.all