Module: GettextI18nRails
- Defined in:
- lib/gettext_i18n_rails.rb,
lib/gettext_i18n_rails/backend.rb,
lib/gettext_i18n_rails/railtie.rb,
lib/gettext_i18n_rails/version.rb,
lib/gettext_i18n_rails/base_parser.rb,
lib/gettext_i18n_rails/haml_parser.rb,
lib/gettext_i18n_rails/slim_parser.rb,
lib/gettext_i18n_rails/gettext_hooks.rb,
lib/gettext_i18n_rails/html_safe_translations.rb,
lib/gettext_i18n_rails/model_attributes_finder.rb
Defined Under Namespace
Modules: GettextHooks, HtmlSafeTranslations Classes: Backend, BaseParser, HamlParser, ModelAttributesFinder, Railtie, SlimParser
Constant Summary collapse
- IGNORE_TABLES =
[/^sitemap_/, /_versions$/, 'schema_migrations', 'sessions', 'delayed_jobs']
- Version =
VERSION = '2.2.0'
Class Method Summary collapse
-
.gettext_extraction_call(msgid) ⇒ Object
Model-name msgids (no ‘|’) are emitted as an n_() singular/plural pair, so the .po file carries msgid_plural for ‘model_name.human(count:)`.
-
.store_model_attributes(options) ⇒ Object
write all found models/columns to a file where GetTexts ruby parser can find them.
-
.warn_legacy_model_msgid(legacy, current) ⇒ Object
Issue #207: model-name msgids changed from the humanized form (“Big car”) to the raw class name (“BigCar”), matching attributes.
Class Method Details
.gettext_extraction_call(msgid) ⇒ Object
Model-name msgids (no ‘|’) are emitted as an n_() singular/plural pair, so the .po file carries msgid_plural for ‘model_name.human(count:)`. Attribute msgids (scoped with ’|‘) have no plural form and stay singular. See issue #207.
33 34 35 36 37 38 39 |
# File 'lib/gettext_i18n_rails/model_attributes_finder.rb', line 33 def gettext_extraction_call(msgid) if msgid.include?('|') "_('#{msgid}')" else "n_('#{msgid}', '#{msgid.pluralize}')" end end |
.store_model_attributes(options) ⇒ Object
write all found models/columns to a file where GetTexts ruby parser can find them
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/gettext_i18n_rails/model_attributes_finder.rb', line 6 def store_model_attributes() file = [:to] || 'locale/model_attributes.rb' begin File.open(file,'w') do |f| f.puts "#DO NOT MODIFY! AUTOMATICALLY GENERATED FILE!" ModelAttributesFinder.new.find().each do |model,column_names| f.puts(gettext_extraction_call(model.to_s)) #all columns namespaced under the model column_names.each do |attribute| f.puts(gettext_extraction_call(model.gettext_translation_for_attribute_name(attribute))) end end f.puts "#DO NOT MODIFY! AUTOMATICALLY GENERATED FILE!" f.puts "{}" end rescue puts "[Error] Attribute extraction failed. Removing incomplete file (#{file})" File.delete(file) raise end end |
.warn_legacy_model_msgid(legacy, current) ⇒ Object
Issue #207: model-name msgids changed from the humanized form (“Big car”) to the raw class name (“BigCar”), matching attributes. The humanized form is still looked up as a fallback; warn once per msgid so apps can migrate their .po files.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/gettext_i18n_rails.rb', line 11 def self.warn_legacy_model_msgid(legacy, current) @warned_legacy_model_msgids ||= {} return if @warned_legacy_model_msgids.key?(legacy) @warned_legacy_model_msgids[legacy] = true warn( "[gettext_i18n_rails] msgid #{legacy.inspect} is deprecated, " \ "re-extract and translate #{current.inspect} instead " \ "(https://github.com/grosser/gettext_i18n_rails/issues/207)" ) end |