Class: I18n::Backend::DiscourseI18n
- Inherits:
-
Simple
- Object
- Simple
- I18n::Backend::DiscourseI18n
- Includes:
- Fallbacks, Pluralization
- Defined in:
- lib/i18n/backend/discourse_i18n.rb
Class Method Summary collapse
Instance Method Summary collapse
- #available_locales ⇒ Object
-
#load_translations(*filenames) ⇒ Object
force explicit loading.
- #pluralize(locale, entry, count) ⇒ Object
- #reload! ⇒ Object
- #search(locale, query) ⇒ Object
Class Method Details
.create_search_regexp(query, as_string: false) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/i18n/backend/discourse_i18n.rb', line 45 def self.create_search_regexp(query, as_string: false) regexp = Regexp.escape(query) regexp.gsub!(/['‘’‚‹›]/, "['‘’‚‹›]") regexp.gsub!(/["“”„«»]/, '["“”„«»]') regexp.gsub!(/(?:\\\.\\\.\\\.|…)/, '(?:\.\.\.|…)') as_string ? regexp : /#{regexp}/i end |
.sort_locale_files(files) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/i18n/backend/discourse_i18n.rb', line 38 def self.sort_locale_files(files) files.sort.sort_by do |filename| matches = /(?:client|server)-([1-9]|[1-9][0-9]|100)\..+\.yml/.match(filename) matches&.[](1)&.to_i || 0 end end |
Instance Method Details
#available_locales ⇒ Object
11 12 13 |
# File 'lib/i18n/backend/discourse_i18n.rb', line 11 def available_locales LocaleSiteSetting.supported_locales.map(&:to_sym) end |
#load_translations(*filenames) ⇒ Object
force explicit loading
23 24 25 26 27 |
# File 'lib/i18n/backend/discourse_i18n.rb', line 23 def load_translations(*filenames) unless filenames.empty? self.class.sort_locale_files(filenames.flatten).each { |filename| load_file(filename) } end end |
#pluralize(locale, entry, count) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/i18n/backend/discourse_i18n.rb', line 29 def pluralize(locale, entry, count) begin super rescue I18n::InvalidPluralizationData => e raise e if I18n.fallbacks[locale] == [locale] throw(:exception, e) end end |
#reload! ⇒ Object
15 16 17 18 19 20 |
# File 'lib/i18n/backend/discourse_i18n.rb', line 15 def reload! @pluralizers = {} # this calls `reload!` in our patch lib/freedom_patches/translate_accelerator.rb I18n.reload! super end |
#search(locale, query) ⇒ Object
55 56 57 58 |
# File 'lib/i18n/backend/discourse_i18n.rb', line 55 def search(locale, query) regexp = self.class.create_search_regexp(query) find_results(regexp, {}, translations[locale]) end |