-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
i18n defaulting to english in main app after upgrading Active Admin #434
Comments
Well, this is interesting since active admin does not set the Can you check what |
Hmm, its value is :en. |
Problem is still here in the 0.3.1. |
I can confirm this. default_locale is still set to what I specify, but I18n.locale switches because of ActiveAdmin: https://gist.github.com/1196193 Will dig into it more. I have a strange feeling it's a gem that it depends on doing the dirty deed. Maybe devise, though I'm not sure why (I use devise in the app already and it's never done this before). Ok, I think this works as a quick hack: 34 config.i18n.default_locale = :'en-US' or whatever you need. Just set the damn locale and be done with it! |
Worked on this a bunch more. Really hard to track down--it's almost like the first call to ActiveAdmin (in standard routes file) requires something to do with I18n, which sets the locale to :en, and thus the default_locale we're setting is ignored. Gotta sleep, eyes crossing at this point, hopefully others can shed some light on it as well. |
To track down where the locale was being updated I did the following: # In gem i18n.
module I18n
class Config
# Sets the current locale pseudo-globally, i.e. in the Thread.current hash.
def locale=(locale)
puts "locale=#{locale}"
raise "money" rescue puts $!.stacktrace
@locale = locale.to_sym rescue nil
end It looks like there is no call to |
@pcreux yep, I did that along the way. There IS a require of i18n, which will do the @@default_locale ||= :en, which locale is then based on. I thought when I commented that out things would be good again, but for some reason no. Definite meh. |
I have similar problem, I wrote about it here: http://stackoverflow.com/questions/7193043/activeadmin-internationalization Can anyone answer that? |
I tracked this bug by raising an exception in I18n::Config#default_locale if @@default_locale isn't initialized.
It looks like routes are initialized before the application actually is, thus leading ActiveAdmin to initialize itself with rails defaults instead of the application's defaults. Do you think this is fixable, somehow? It looks some translations (like the menu) are done when ActiveAdmin loads, which is wrong (what happens if a user can choose the locale?). Translations must be done on display. It think that would actually fix the problem. |
Removing the require i18n does not solve the problem (in the case of a Rails app of course), locale is still defaulting to english. |
+1 config.i18n.default_locale = :"en-GB" After installing activeadmin I am finding that methods such as (I'm guessing that, in our development environment, the |
I think I've found a workaround for this: I've created a new file config/initializers/001_i18n.rb ('001' filename prefix is an attempt to ensure this file gets loaded before active_admin.rb) # The default locale is :en-GB and all translations from config/locales/*.rb,yml are auto loaded.
I18n.default_locale = :'en-GB'
I18n.load_path += Dir[Rails.root.join('config', 'locales', '*.{rb,yml}').to_s]
I18n.reload! |
+1, same issue here. config.i18n.default_locale = :fr I18n.locale = config.i18n.locale = config.i18n.default_locale Ok it's ugly, but everything is working now! :) |
The problem actually is located in resource_name and pural_resource_name methods of the ActiveAdmin::Resource::Naming module. These methods are used to determine the name of the resources and rely on model_name (from ActiveModel::Naming) to get translated names. The problem is that resource_name and plural_resource_names are called when ActiveAdmin is initialized when routes are initialized and before rails is actually initialized. Thus the default locale has never been set but ActiveAdmin already called model_name which called I18n.t('activerecord.models.name.class_name') which eventually called I18n.default_locale which is set to the library default: en. Even if rails initialized routes after it initialized the whole application, there is another side effect: you can't change the locale in production on a per-user basis, because resource names are cached here and there (eg: in Resource, Menu, etc). The solution would be for resource_name and plural_resource_name to no longer rely on model_name and to add a human_name method instead, that would be called in views, when necessary and on demand (no cache, never). I did that brute-force in a fork with a bunch of other I18n related things (I needed it ASAP, don't merge any of it as-is) : https://github.com/ysbaddaden/active_admin |
I've done the following workaround: I've made an initializer ( I18n.locale = :nl # or whatever your default locale is
I18n.load_path += Dir[Rails.root.join("config/locales/**/*.yml")]
I18n.reload! |
Used same solution as @iain, subscribing for this issue in the hopes of removing the ugly override in the future. |
This is very weird. Did a session with ruby-debug, with a ApplicationController#index just printing the values of I18n.default_locale and I18n.locale. Ruby-debug says I18n.default_locale and I18n.locale was "de" (which I had set it to). Any clues to why I18n called in the controller and I18n called the debugger is showing different results? Hard bug to track down :) |
Same solution as @iain. Hoping you fix it soon. |
+1 |
I have a similar problem, but @iain workaround doesn't work for me, because I use a scope in the routes for I18n. I set the I18n.locale in the ApplicationController and it has no effects in the ActiveAdmin view elements translations (e.g. menu model name). |
+1 and trying the proposed workarounds. |
The problem happens only on Thin. On Webrick everything works fine. |
@iain, your workaround works for me as well, thanks! |
I can reproduce this issue. Adding this to an initializer fixes it though: I18n.locale = :nl # or whatever your default locale is
I18n.load_path += Dir[Rails.root.join("config/locales/**/*.yml")]
I18n.reload! |
Ran into this problem today... Still present :-/ |
I have this problem still with activeadmin 0.4.4 and rails 3.2.3 |
+1
|
Please try my pull request #1448 as I think it will fix this. You will need to copy your language's active_admin translations to |
I get this to work with an
|
See the issues referenced from #1448. Non-English users shouldn't all have to write a |
There are lots of similar issues in AA so i put it here. I fixed my problems with method set_locale as klebershimabuku wrote but i put the method not in ApplicationController because it is never called from there but in initializers/active_admin.rb in ActiveAdmin::ResourceController.class_eval do protected Set ru locale by default for ActiveAdmindef set_admin_locale end |
@pi3r thank you now works |
Hi.
I upgraded Active Admin from 0.2.2 to 0.3.0, and now my main application defaults to English when looking for translations.
In my config/application.rb there is still:
The text was updated successfully, but these errors were encountered: