ruby - rails 4, globalize gem, how to setting default locale -


I am using a globalized gem to support multiple locales.

The config / locales directory contains three files

  en.yml, ja.yml, ch-HK.yml  

and My routing file is

 . ... Root: from = & gt; 'Main # index' ,: locale = & gt; : N Scope ": Locale", Locale: /#{I18n.available_locales.join("|")}/ To name namespace (: API) {resource: badges} name space (: API) {resource: get event: list ,: On = & gt; : Archive end} end ....  

Setting my default path (/) default locale

But I do not know the default locale in the API_controller How to set it

me

  /api/events.json -> gt; & Gt; /en/api/event.json/ja/api/events.json - & gt; & Gt; /ja/api/events.json  

Is not it accepted in the rail project?

Will add: locale / API ~~?

Each request is passed through an administrator and it is the place to set the default locale You need to do this by setting I18n.locale =: locale . There are several ways to detect user locale, i.e. request header, user preferred language (if logged in and archived). You can also check for the request format (in the case of APIs) and set the locale accordingly. Setting a locale for Url is not necessary here.

This is a piece of place that I am using to set the locale:

  before_filter: set_locale def set_locale if defined? (Parameters) & amp; Param [: locale] I18n.locale = params [: locale] alsf current_user & amp; Current_user.language_id.present? I18n.locale = current_user.language.code elsif Defined (requested) I18n.locale = extract_locale_from_accept_language_header end I18n.locale || = I18n.default_locale = I18n.locale =? En until valid_languages.include (I18n.locale.to_sym) end  

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -