sh 流星:国际化(i18n)。更多:http://journal.gentlenode.com/meteor-9-internationalization-i18n/

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 流星:国际化(i18n)。更多:http://journal.gentlenode.com/meteor-9-internationalization-i18n/相关的知识,希望对你有一定的参考价值。

<!--
  9. Inside your Template, we just have to use the i18n helper.
     Note 1: if your translated strings include html tags, use the triple brackets {{{ }}}.
-->


<template name="Homepage">
  <h1>{{i18n 'homepage.title'}}</h1>
  <h2>{{i18n 'homepage.subtitle'}}</h2>
</template>
# The following code should only be available to the server. (inside your server directory)


# 8. We save the user language during registration server-side. (see step 6.)


Accounts.onCreateUser (options, user) ->
  # do you stuff as usual
  language = options.language
  user.profile = { language: language }
  
  return user
# The following code should only be available to the client. (inside your client directory)


# 5. Set the relevant language client-side.


Meteor.startup ->
  if Meteor.isClient
    if Meteor.user()
      language = Meteor.user().profile.language  # see step 6.

    else
      # detect the language used by the browser
      language = window.navigator.userLanguage || window.navigator.language
      language = getLanguage language

    i18n.setLanguage language


# 6. Let's save the user language during registration by passing the language to Accounts.createUser()


Template.AccountSignUp.events
  'submit #signUpForm': (evt) ->
    # do your stuff as usual for register your users
    language = i18n.getLanguage language
    options = { email: email, password: password, language: language }

    Accounts.createUser options, (err) ->
      # handle the errors as usual.


# 7. Let's load the relevant user language during sign in.


Template.AccountSignIn.events
  'submit #signInForm': (evt) ->
    # do your stuff as usual for login your users
    Meteor.loginWithPassword email, password, (err) ->
        if not err
          language = Meteor.user().profile.language
          i18n.setLanguage language
# The following code should be available to the client and the server. (i.e.: inside your lib directory)


# 2. Set a default language.


i18n.setDefaultLanguage 'en_US'


# 3. A little helper to retrieve the locale according to the language. (see step 5. for the use)


@getLanguage = (language) ->
  if language.match /fr/
    language = 'fr_FR'

  else
    language = 'en_US'

  return language
  

# 4. Our translated strings.


i18n.map 'en_US', homepage:
  title: 'Meteor is awesome.'
  subtitle: 'A better way to build apps.'
  
i18n.map 'fr_FR', homepage:
  title: 'Meteor est génial.'
  subtitle: 'Une meilleure manière de construire des applications.'
# This little gist shows how to easily internationalize your application using the meteor-just-i18n package.
# Package repository: https://github.com/subhog/meteor-just-i18n/


# 1. Adding the package.


$ meteor add anti:i18n

以上是关于sh 流星:国际化(i18n)。更多:http://journal.gentlenode.com/meteor-9-internationalization-i18n/的主要内容,如果未能解决你的问题,请参考以下文章

JavaWeb 之 i18N 国际化

为什么国际化缩短为“i18n”?

I18N 国际编码

实战:第二十章:i18n国际化(已实现中文,英文,波兰文)

实战:第二十章:i18n国际化(已实现中文,英文,波兰文)

Cocos2d-x支持 i18n 国际化——i18n XML 解析生成头文件