Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
@app.constant('LOCALES', {
  'locales': [
    { id: 'en-gb', name: 'English (UK)' },
    { id: 'zh-ch', name: 'Chinese (China)' }
  ],
  'preferredLocale': 'en-gb',
  'fallbackLanguage': 'en-gb'
})

@app.config(($translateProvider, LOCALES) ->
  # Path to translations files
  $translateProvider.useStaticFilesLoader({
    prefix: '/locales/',
    suffix: '.locale.json'
  })

  $translateProvider.fallbackLanguage(LOCALES.fallbackLanguage)
  $translateProvider.useSanitizeValueStrategy('sanitizeParameters')
  $translateProvider.useMissingTranslationHandlerLog()
)

...

Code Block
# Configure angular translate depending on the locale used in the path
@app.run(($window, $translate, LOCALES) ->
  # Get current path (eg. "/en-gb/dashboard/" or "/dashboard/")
  path = $window.location.pathname

  # Extract the language code if present
  re = /^\/([A-Za-z]{2}-[A-Za-z]{2})\/dashboard\//i
  found = path.match(re)

  if found?
    # Ex found: ["/en-gb/dashboard/", "en-gb", index: 0, input: "/en-gb/dashboard/"]
    locale = found[1]
  else
    # Default language
    locale = LOCALES.preferredLocale

  $translate.use(locale)
)

...

The URL should be localised in order for the customers to copy and paste URL and keep the localisation when the page is loaded. If the locale is missing in the URL, a default locale must be loaded (eg. "en-gb").

mno-enterprise configuration

...

mno-enterprise gem contains a tool to convert multiple en-gb.yml files into one json file en-gb.locale.json:

Code Block
$ rake mnoe:locale:generate

As an example, en-gb.yml file:

Code Block
en-gb:
  mno_enterprise:
    templates:
      dashboard:
        account:
          my_account: My Account
          personal_information: Personal Information
          user_form_name: Name
          user_form_surname: Surname

will be converted to public/locale/en-gb.locale.json:

Code Block
{
  "mno_enterprise.templates.dashboard.account.my_account": "My Account",
  "mno_enterprise.templates.dashboard.account.personal_information": "Personal Information",
  "mno_enterprise.templates.dashboard.account.user_form_name": "Name",
  "mno_enterprise.templates.dashboard.account.user_form_surname": "Surname"
}