Missing en-UK.yml file for Rails app - ruby-on-rails

I'm trying to switch one of my websites into en-UK so that I get the correct date and currency formats etc...
I have found this yaml file:
http://github.com/mattetti/globalite/blob/master/lang/rails/en-UK.yml
Any ideas if there is a better one to use?
I also checked here but could not see it:
http://github.com/svenfuchs/rails-i18n/tree/master/rails/locale
Thanks,
Nick

I have found a better solution than to keep a duplicate version of en.yml and simply change the $ to £.
There is a plugin that lets you only override the values you require:
http://github.com/javan/rails-i18n-translation-inheritance-helper
config/environment.rb
config.i18n.default_locale = 'en-UK'
and then create:
config/locales/en-UK.yml - for special cases
en-UK:
number:
currency:
format:
unit: '£'
format: '%u%n'
config/locales/en.yml - for all English translations
en:
btn_submit: Submit
This works a treat and will also mean that I don't need to maintain the file apart from any special cases like above.
View
=t 'btn_submit' #Submit
=h number_to_currency(#price, :precision => 0) #£1,000
Hope this helps others as it took a while to find a solution.

I think you're looking for en-GB :)
https://github.com/svenfuchs/rails-i18n/blob/master/rails/locale/en-GB.yml

Related

RAILS I18n: How to use # in translation key?

Here is in our yml file:
Or make up unique one like login#a.com : 'test'
But here is the error on view page for I18n.t("Or make up unique one like login#a.com"):
translation missing: zh-CN.Or make up unique one like login#a.com
What causes the missing translation of t()?
UPDATE:
Just verified that the problem was caused by # sign. Now the question becomes how to use # in translation key.
I highly recommend the Rails i18n guide for beginners.
It will help you understand how to structure your files, how to setup routes to support a locale param, how to set the locale, and other useful tips.
The t helper is not intended to take a string of text to translate. It takes a yaml key and outputs the translated text from a locale file.
You want to structure your yaml file as such:
config/locales/en.yml
en:
some_key: hello world
config/locales/cn.yml
cn:
some_key: hello in Chinese
Then using it in your views
<%= t :some_key %>
Based on the I18n.locale setting, the t helper will look up :some_key in the corresponding locale file and output the translated text.

Error I18n::InvalidLocaleData

I want use I18n and I already follow on how to do that from railscast but the thing gone wild and I don't know where the mistake, had tried check the format, tried several ways but still can't be done.
my en.yml
en:
category:
index:
title: "Listing Categories"
name: "Name"
is_active: "Is Active"
my view
<%= t 'category.index.title' %>
But return I18n::InvalidLocaleData in Categories#index and can not load translations from /home/lenovo/cost_control/config/locales/en.yml, expected it to return a hash, but does not
I had try on my en.yml just:
en:
title: "Listing Categories"
and can work perfectly, but when I adding more line, just return me those error. I'm sorry I just not so advanced yet in rails, thank you for the help you guys :D really.
It seems your YAML is broken. Didn't you use tabs instead of spaces?
You can use YAMLlint to check YAML for validity.
The validator Ilya recommends seemed pretty basic and not so great
Found this one which is better https://codebeautify.org/yaml-validator

Share translations between multiple locales in Rails3

I have locales that come in the form of en-GB, en-US, de-DE, de-AT, de-CH etc..
Now the issue is that de-DE, de-AT, de-CH all share the same translations.
So having to define them multiple times is annoying and not very DRY.
Before anyone suggests just using :de as locale, I can't. That's how I did it before and due to some business logic I can't change the new en-GB format was forced onto me.
Help would be very much appreciated.
If you're using YAML for you localization then you already have necessary tools. YAML allows you to write something like mixins:
en: &english
hello: Hello, %{username}!
en-GB:
<<: *english
en-US:
<<: *english
I hope you got the idea of DRYing here.
Still DRY still but more importantly your translations aren't duplicated in memory :
Create an i18n initializer that includes fallbacks :
require "i18n/backend/fallbacks"
I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
And move your translations into de: and en: locales.
A call like this
I18n.t :foo, :locale => 'de-AT'
will first look for de-AT.foo and providing there is no match, will look for de.foo.
More info on the i18n wiki.

Supporting different locale regions using Rails i18n

I'm using the standard Rails I18n API to localise some of our views. This is working really well, but we now have a few use cases for regional changes to the en locale.
The API guide mentions that this isn't supported directly, and other plugins should be used. However, I'm wondering whether there's a simpler way to do this.
I already have en.yml, so in theory I could just create en-AU.yml and en-US.yml which are effectively clones of en.yml but with a few regional changes applied. I could then add additional English - American and English - Australian options to our configuration which would map to the new region-specific locales and allow users to use a region-specific locale.
The only problem I can think of with this is that it isn't DRY -- I would have duplicate translations for all common English words. I can't see a way around this.
Are there any other disadvantages to this approach, or should I just bite the bullet and dive into one of the plug-ins such as Globalize2 instead?
The rails-i18n-translation-inheritance-helper is getting a bit old now, so here's my approach for a Rails 3.2 project.
If you keep both en-US and en-AU in the same en.yml file you can use the yml repeated node to have a super en section:
For example:
en: &en
errors:
messages:
expired: "has expired, please request a new one"
not_found: "not found"
en-US:
<<: *en
en-AU:
<<: *en
errors:
messages:
not_found: "tis not found"
I'm using translation inheritance helper plugin for this.
In newer versions of Rails/i18n, they've added a fallback feature. Works similar to the outdated translation inheritance helper gem
see this answer for more info: Fall back to default language if translation missing

Ruby On Rails: pluralize for other languages

I am building apps for a non-english audience. Right now, I use english nouns to name my models, yet I prefer to use native dutch ones. As the convention uses the plural of the class name for tables, I assume it is the pluralize method inside Rails (where it resides, I wouldn't know). How can I change the pluralize method and where is it located? Would this break Rails?
I am using Rails 2.3.5 and Ruby 1.8.7
Example:
The Book class becomes books now.
My Boek class becomes boeks, but it is grammatically correct to use boeken
Add your rules to an inflections.rb file in config/initializers. See the API documentation:
ActiveSupport::Inflector.inflections do |inflect|
inflect.plural 'boek', 'boeken'
end
Perhaps won't help you because you want Dutch language, but for Spanish, French, Kazakh, Turkish or Norwegian, there is this:
https://github.com/davidcelis/inflections
This is not answering the question specifically, but if a language has too much irregularities one can disable the inflector according to the discussion.
ActiveRecord::Base.pluralize_table_names = false
In addition, as far as views are concerned my preferred way of dealing with pluralizing foreign strings is i18n pluralization. Take a look at a straightforward example below.
# config/locales/en.yml
en:
message:
one: You have 1 message #Your foreign string
other: You have %{count} messages #Your foreign string
Then in view you can do
# app/views/messages/index.html.erb
<%= t("message", count: current_user.messages.count) %>
Check official documentation.
Hope that helps!

Resources