-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from AndyObtiva/development
Fix i18n issues + Refactorings
- Loading branch information
Showing
18 changed files
with
169 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,5 @@ | |
|
||
module Kuiq | ||
WINDOW_WIDTH = 900 | ||
WINDOW_HEIGHT = 450 | ||
WINDOW_HEIGHT = 500 | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Any methods defined here are available everywhere (both Models & Views) to provide extra convenience | ||
# for handling cross-cutting concerns like logging and i18n. | ||
# | ||
# That said, defining Kernel methods must be done sparingly as it can be tough for codebase | ||
# newcomers to figure out that global methods live here, and it would be better for maintainability | ||
# in general to call methods on objects instead of inheriting global utility methods. | ||
module Kernel | ||
# We will return Sidekiq.logger instead of Glimmer::Config.logger | ||
# because in general, GUI error logging is at the error level | ||
# and Sidekiq logging is at the info level, and we do not want | ||
# to see GUI info logging as it can be very verbose. | ||
# | ||
# In the future, if there is a need to unite the two loggers, we could | ||
# set `Glimmer::Config.logger = Sidekiq.logger` right after loading | ||
# both the sidekiq and glimmer-dsl-libui gems. | ||
def logger | ||
Sidekiq.logger | ||
end | ||
|
||
def t(msg, options = {}) | ||
Kuiq::I18n.t(msg, options) | ||
end | ||
|
||
# Inverse-translates (e.g. for "Tableau de Bord" in fr, we get "Dashboard") | ||
def it(msg, options = {}) | ||
Kuiq::I18n.it(msg, options) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# frozen_string_literal: true | ||
|
||
module Kuiq | ||
class I18n | ||
LOCALES = "./locales" | ||
|
||
class << self | ||
# Use Sidekiq's i18n with locale files in sidekiq/web/locales | ||
# Note task in Rakefile to refresh locale files. | ||
def current_locale | ||
@locale ||= begin | ||
x = (ENV["LANGUAGE"] || ENV["LANG"] || "en").downcase.tr("_", "-") | ||
loop do | ||
break "en" if x.size < 2 | ||
break x if File.exist?("#{LOCALES}/#{x}.yml") | ||
# dumb brute force heuristic: look for locale files | ||
# that match the longest LANG prefix, necessary to serve | ||
# more complex lang groups like zh and pt. | ||
x = x[0...-1] | ||
end | ||
end | ||
end | ||
|
||
# Translates msg string for current locale (e.g. for "Dashboard", we get "Tableau de Bord" in fr) | ||
def t(msg, options = {}) | ||
string = strings(current_locale)[msg] || msg | ||
if options.empty? | ||
string | ||
else | ||
string % options | ||
end | ||
end | ||
|
||
# Inverse-translates msg string for current locale (e.g. for "Tableau de Bord" in fr, we get "Dashboard") | ||
def it(msg, options = {}) | ||
inverted_strings = inverted_strings(current_locale) | ||
msg_without_underscores = msg.to_s.sub('_', ' ') | ||
string = inverted_strings[msg] || inverted_strings[msg_without_underscores] || msg | ||
if options.empty? | ||
string | ||
else | ||
string % options | ||
end | ||
end | ||
|
||
private def strings(lang) | ||
@strings ||= {} | ||
@strings[lang] ||= [LOCALES].each_with_object({}) do |path, global| | ||
Dir["#{path}/#{lang}.yml"].each do |file| | ||
strs = YAML.safe_load_file(file) | ||
global.merge!(strs[lang]) | ||
end | ||
end | ||
end | ||
|
||
private def inverted_strings(lang) | ||
@inverted_strings ||= {} | ||
@inverted_strings[lang] ||= strings(lang).invert | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.