Writing Language Files - Nemo64/meteor-translator GitHub Wiki

This Package is essentially a key value storage for text with a few more features. The best way to begin is to define keys and values. For that the best format to use is yaml but it is also possible to use json if you prefer it. However you should prefere yaml as it is easier to write and maintain.

To get started create a public.en_US.lang.yml. That name consists of 3 parts:

  1. public is the name with which you'll address it later. It's is referred to as namespace.
  2. en_US identifies the language of the content will have. Look at this guide for picking the right language code.
  3. lang.yml defines it as a language file in the yaml format. lang.json is also possible.

How to split your files

You shouldn't use too many files as each one is another request (for the frontend at least). I recommend that you use a schema comparable to this:

  • public.en_US.lang.yml for everything that everyone can access
  • user.en_US.lang.yml for content most users won't even see if they don't have an account
  • mails.en_US.lang.yml for mails that the user won't see anyways as the server should send them

Of course this is not a must. If you have only a few strings (kb) it can safely all be one file.

Note: Future version will concatenate translations for one language so that it becomes a better practice to split files more often. Packages should always use there own translation file and it should be possible to overwrite translations then. This is already possible but will take a lot of files.

Examples

An example yaml file

language/public.en_US.lang.yml

user_login:
  title: "login area"
  label:
    username: "username"
    password: "password"
    no_account: "No account yet? Create one right now!"
    lost_password: "Did you loose your password?"
    submit: "login"
  errors:
    wrong_login: "Login into account failed!"
    enter_username: "please enter a username"
    enter_password: "please enter a password"

An example json file

language/public.en_US.lang.json

{
  "user_login": {
    "title": "login area",
    "label": {
      "username": "username",
      "password": "password",
      "no_account": "No account yet? Create one right now!",
      "lost_password": "Did you loose your password?",
      "submit": "login"
    },
    "errors": {
      "wrong_login": "Login into account failed!",
      "enter_username": "please enter a username",
      "enter_password": "please enter a password"
    }
  }
}

Under the hood

Your files will never see the client like you wrote them. They go though a plugin which will generate a json file out of them (no matter the input format). This json file will have the keys joined together so a look-up can be faster. Also other features will do some pre-processing before the file gets send to the client.