rails-i18n

How to add values dynamically to I18n?

我是研究僧i 提交于 2019-12-06 07:18:28
问题 I have many ymls in my rails app, and i want to put some of them in other service, so that i can call this from multiple places. the response of this call will be a hash. {"en" : {"test" : {"text1" : "hi english"}, {"text2" : "mambo number %{num}"} }, "es" : {"test" : {"text1" : "hi espaniol"}, {"text2" : "mamboes numeros %{num}"} } } is there a way i can load that hash into I18n translations like I18n.add_translations(some_hash) so i can access them with I18n.t("test.text1") I18n.t("test

How to configure locale aliases using i18n & rails?

点点圈 提交于 2019-12-04 19:00:39
I am working on a rails app (3.2.13) that is being translated into several languages, including (one of the 3 available flavours of) Norwegian. On public pages, the app uses the browser's language settings to set locale. Most browsers offer 3 separate Norwegian shortcodes: no , nb & nn . The translations we have are in nb , but I think it would be best if no & nn also defaulted to nb . That way, if a user's browser language preferences were set to no then en , the app would try to supply nb Norwegian first, instead of skipping straight to English. Is it possible to configure a list of

Rails 4 i18n, how to translate routes where subdomain is used for the locale

落花浮王杯 提交于 2019-12-04 13:27:47
问题 I am using subdomains to determine the locale in a Rails 4 website. I have this working with a locale switcher exactly the way I want it but now I need to translate the routes and I'm not sure about the best way to proceed. I have looked the https://github.com/kwi/i18n_routing i18n routing gem but this doesn't work with subdomains, it seems to change the path by adding /locale which is not what I need. Other gems seem to be out of date with Rails 4. Edit Basically I want to be able to use the

Rails I18n validation deprecation warning, after setting enforce_available_locales = true

。_饼干妹妹 提交于 2019-12-04 03:09:50
问题 You placed something like this in config/application.rb I18n.enforce_available_locales = true config.i18n.load_path += Dir[Rails.root.join('config/locales/', '*.{rb,yml}').to_s] config.i18n.available_locales = ['es-LA', :en] config.i18n.default_locale = 'es-LA' And the warning still appears: [deprecated] I18n.enforce_available_locales will default to true in the future. 回答1: The reason is due to a bug with locales that have the language-country format. The good news is that it has been fixed

Access translation file (i18n) from inside rails model

[亡魂溺海] 提交于 2019-12-03 22:06:19
What I have in my model is: def body_color_enum [ ['Aqua', '#009c9c'], ['Grey', '#6d6e71'], ['Yellow', '#ffe600'], ['White', 'white'] ] end I want these values to come from the translation file 'en.yml' en: group: hero: hex1: '#6d6e71' name1: 'Dark grey' hex2: '#ccc' name2: 'Light grey' hex3: '#0099ce' name3: 'Blue' hex4: '#ffffff' name4: 'White' I have tried this: def body_color_enum [ [t('group.hero.name1'), '#009c9c'], ['Grey', '#6d6e71'], ['Yellow', '#ffe600'], ['White', 'white'] ] end But i get this error: undefined method `t' for #<Group:0x007fabad847ac8> So what I'm asking is how can I

Interpolation in I18n array

半世苍凉 提交于 2019-12-03 03:44:44
I'm using arrays in a locale file to be able to generate blocks of text in various output methods (ActionMailer templates, Prawn documents, HAML templates) that are locale-specific. It works perfectly, but sometimes I want to pass variables into these I18n calls. However, this doesn't work. Say my locale file looks like this: en: my_array: - "Line 1" - "Line 2" - "Line 3 has a %{variable}" - "Line 4" I want the output of I18n.t('my_array', :variable => 'variable named variable') to be as follows: ["Line 1", "Line 2", "Line 3 has a variable named variable", "Line 4"] However, the output is: [

Rails I18n validation deprecation warning, after setting enforce_available_locales = true

会有一股神秘感。 提交于 2019-12-01 16:52:03
You placed something like this in config/application.rb I18n.enforce_available_locales = true config.i18n.load_path += Dir[Rails.root.join('config/locales/', '*.{rb,yml}').to_s] config.i18n.available_locales = ['es-LA', :en] config.i18n.default_locale = 'es-LA' And the warning still appears: [deprecated] I18n.enforce_available_locales will default to true in the future. The reason is due to a bug with locales that have the language-country format. The good news is that it has been fixed already. This was reported in Github with Issue 13164 and fixed with pull request 229 . If you want to grab

How to include ё in [а-я] regexp char interval

ぐ巨炮叔叔 提交于 2019-12-01 02:10:14
Russian alphabet includes the letter ё , which was undeservedly forgotten at beggining of computing. So, if i want to use a regexp with character diapason, I must mention this letter separately: [а-яА-яёЁ] instead of: [а-яА-Я] example: lets we have string "Верёвочка - 12" and need to parse only word by regular expression: word = "Верёвочка"[/а-яА-Я/] # => "" word = "Верёвочка"[/а-яА-ЯёЁ/] # => "Верёвочка" How can I upgrade regexp class in Ruby or Ruby on Rails to resolve this problem? This is cool - I had never thought that much about character ranges in unicode. It seems that for some reason

How to retrieve all translations from yml files in Rails I18n

有些话、适合烂在心里 提交于 2019-11-30 11:19:44
问题 I'm guessing that rails stores all the parsed translations yml files in a sort of array/hash. Is there a way to access this? For example, if I've a file: en: test_string: "testing this" warning: "This is just an example Could I do something like, I18n.translations_store[:en][:test_string] ? I could parse the yml file with YAML::load, but in my case I've splitted the yml files in subfolders for organization, and I'm pretty sure that rails already parsed them all. 回答1: You got to call a private

How to retrieve all translations from yml files in Rails I18n

怎甘沉沦 提交于 2019-11-29 23:50:53
I'm guessing that rails stores all the parsed translations yml files in a sort of array/hash. Is there a way to access this? For example, if I've a file: en: test_string: "testing this" warning: "This is just an example Could I do something like, I18n.translations_store[:en][:test_string] ? I could parse the yml file with YAML::load, but in my case I've splitted the yml files in subfolders for organization, and I'm pretty sure that rails already parsed them all. You got to call a private method on the backend. This is how you get access: translations = I18n.backend.send(:translations)