Giter Club home page Giter Club logo

meteor-i18n's Introduction

Notes for updating to Meteor 0.9.0

This package is now called anti:i18n.

Internationalization for Meteor

A simple (The simplest possible? Perhaps) i18n package for Meteor.

API

i18n(label)

Get your localized text in Javascript.

Example: i18n('store.purchase');.

{{i18n label [params...]}}

Get your localized text in Handlebars.

Example: {{i18n "store.purchase"}}.

Example: {{i18n "path" "here" "there"}}

{{i18n "sayHello" userName}}

Provide arguments

i18n.map(language, map)

Add new text map.

Example:

i18n.map('en', {
  sayHello: 'Hi {$1}',
  store: {
    purchase: 'buy now',
    basket: 'basket',
  },
  path: 'From: {$1} to: {$2}',
  'shipping.options': 'shipping',
});

i18n.setLanguage(language)

Set your current language.

Example: i18n.setLanguage('en_US').

i18n.setDefaultLanguage(language)

Set your default language. This is the base language, if there is no translation to the currently chosen one, default language will be used instead.

Example: i18n.setDefaultLanguage('en_US').

i18n.getLanguage()

Get the current language code.

Advanced options

i18n.showMissing(missing)

Decide whether to show a warning when there's no translation in the current and default language.

  • false: Display nothing (default).
  • true: Display the placeholder in default format, [<%= label %>].
  • String: Display the placeholder in custom format. The given string will be used as underscore template with the following parameters:
    • label
    • language
    • defaultLanguage

Example: i18n.showMissing('[no translation for "<%= label %>" in <%= language %>]');

meteor-i18n's People

Contributors

alexandre-georges avatar apendua avatar dandv avatar derhackler avatar pahans avatar queso avatar softwarerero avatar subhog avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

meteor-i18n's Issues

Fallback language

Hi

Is it possible to use a fallback language instead of showMissing? So one could use a partial translation in one language, and english where it's missing?

AutoDetection

Just wanted to ask if this could be included into the package directly or is it better to create an own package for this?

based on navigator.language
Then the developer could just set this feature on/off with:
i18n.autoDetect = true/false (default false)

For the developer it could also mean, that the language string in the i18n.map method should be a standardized iso language string.

How to handle markup tags

I'm coming to the i18n from .po and .mo files, so I'm not sure how to handle markup tags in this placeholder model.

I'd typically embed some simple HTML inside the translated string. For example get your <strong>toys</strong> here. But with blaze, that doesn't work, the tag gets output. What's the best way to approach this with just-i18n?

PS> Thanks for an awesome piece of software, helping to make Meteor rock onwards. ๐Ÿ‘

where and structure for i18n?

where and structure for i18n?
both or client or sever folder for this.
and the structures ????????????

both/i18n/en.i18n.json, ...kh.i18n.json

Empty key is treated as not exsisting

Hi,

When I add empty key:

i18n.map('en', {
    key: ""
});

with option i18n.showMissing(true); the handlebars helper {{i18n 'key'}} is returning the key not empty string. Same goes to the i18n function. I think it's bug; and I just don't have time to write fix and make pull request on my own :)

Cheers

Question - Is it safe to use the triple brackets to render HTML strings?

Hello and thank you for this package!

I was wondering if it was safe to use the triple brackets to render HTML strings like so:

# in a coffee file
i18n.map 'en_US', homepage:
  title: '<span class="bold">Meteor is</span> awesome!'

# in a template
{{{i18n 'homepage.title'}}}

As the user can easily change the content of homepage.title, it is maybe in this case a more general question, is it safe to use the triple brackets in Meteor or should we avoid such practice?

Allow raw HTML in i18n message?

For example, if I have a multi-paragraph message need to be translated, I'll have this in my i18n.js:

i18n.map('en', {
  great_text: '<p>paragraph 1</p><p>paragraph 2</p>'
});

But then {{i18n "great_text"}} will escape html tags and display following to user:

<p>paragraph 1</p><p>paragraph 2</p>

Is it possible to disable html escaping and just insert raw html into page?

Default language

I have debugged your code and I am not sure about this part :
i18n.setDefaultLanguage = function(language) {
i18n._default = 'language';
i18n._dep.changed();
};

I think it should be : i18n._default = language;

i18n in <title> tag

Hi,

I'm having trouble with this usage:

<head>
    <title>{{i18n 'key'}}</title>
</head>

the browser does not change this to translated message; it keeps {{i18 'key'}} as title. Is this bug or am I doing something wrong?

Cheers,
Khrone

autoform reactive labels

I am using "just-i18n" with "meteor-autoform" and I want my labels to be reactive when language changes. Assigning i18n('key') to the labels defined in my "SimpleSchemas" did not help.

Isn't the global javascript function i18n() supposed to be reactive ??

I tried wrapping i18n() inside another global function trans() which returns a callback for i18n() and magically this fixed the problem. I don't know why this helped and if this is the correct way to do it ??!!

Here is my code:

// Translate reactively
transr = function(key) {
    return function() {
        return i18n(key);
    };
};

Schema.user = new SimpleSchema({
    email: {
        type: String,
        label: transr('email'),
        regEx: SimpleSchema.RegEx.Email,
    },
    //...
});

P.S. I am new to reactive programming :)

How to import the package in tests

Hi @apendua, thanks for your great work.

I'm hoping to compare a i18n value against a test value, but cannot get package to be imported as keeps saying. Error: Cannot find module 'meteor/anti:i18n'.

Tests are being ran via npm run test:dev-chimp:

"test:dev-chimp": "chimp --ddp=http://localhost:3000 --path=tests --watch --chai --mocha"

Code when testing (been shortened):

import { assert } from 'chai';
import i18n from 'meteor/anti:i18n';

...

it('Correct page title', function() {
   let title = browser.getTitle();
   expect(title).to.equal(i18n("pages.settings.user.settings"))
});

...

Any help greatly appreciated :)

little helper, comes in handy

just a thought for a little trick to share with the community or add as feature to your source.
maybe you'll share it on your README.md

In order to capitalize the first Character of any i18n string you can add your own little helper:
UI.registerHelper('I18n',function(string) { return i18n(string).charAt(0).toUpperCase() + i18n(string).slice(1); });

note the use of UPPERCASED I18n instead of i18n

i18n.getMap() ?

What about adding a function to get the map ?
The use would be to check which languages are in the map.

Language selection disappears when reloading the page.

Hi,

I tried to make a 2 languages application (en & fr).

When I change the language to French, there's no problem, the display rerenders with French values, I can navigate throughout the application... Until I reload a page: when pressing F5, the language preference is reset to default.

Great module.
Best regards.

PS: I'm using Iron Router.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.