Giter VIP home page Giter VIP logo

i18next-node's Introduction

i18next: learn once - translate everywhere Tweet

CI Code Climate Coveralls Package Quality cdnjs version npm version npm

i18next is a very popular internationalization framework for browser or any other javascript environment (eg. Node.js, Deno).

ecosystem

i18next provides:

For more information visit the website:

Our focus is providing the core to building a booming ecosystem. Independent of the building blocks you choose, be it react, angular or even good old jquery proper translation capabilities are just one step away.

Documentation

The general i18next documentation is published on www.i18next.com and PR changes can be supplied here.

The react specific documentation is published on react.i18next.com and PR changes can be supplied here.


Gold Sponsors


From the creators of i18next: localization as a service - locize.com

A translation management system built around the i18next ecosystem - locize.com.

locize

With using locize you directly support the future of i18next.


i18next-node's People

Contributors

alexandrevoilab avatar alexandrusavin avatar arlolra avatar benmarten avatar deedubs avatar djebbz avatar eymengunay avatar jamuhl avatar jul13nt avatar kiko avatar luileito avatar marcbachmann avatar mitar avatar paulgrock avatar pauliusuza avatar pvorb avatar raigen avatar redbugz avatar robrich avatar seanadkinson avatar tsabolov 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

i18next-node's Issues

Change language query parameters

Could a init option be added so that we can change the language parameter so this is possible:

from

?setLng=sv-SE

to

?lang=sv-SE

Or else I would have to change the setLgn to lang in a middleware myself but I thought this could/should be part of the library.

When translation key missing, is it possible to have the key name as translation ?

That's already the case, right but it seems to be different if you're changing the language on the fly (through a popup menu with language choice, for instance)
By default, the language is set to en-GB. All the keys are there in the translation.json.
when the user change to es-ES, for example, where not all the keys are present, the translation remains on english.
Probably what you wish on PROD env but not really interesting on DEV.
I've tried to play with the defaultValue in the options for init but it appears it's not use deep down in _translate().
Any thoughts for me to try to solve this ?
Cheers.

edit: just thought that the way I change the language on-the-fly may be not the right one so here it is:
i18n.setLng(lang, function(t) {
$(document).i18n();
});
and yes, I'm on the browser side.

useLocalStorage prevents client from fetching translations

The browser side option useLocalStorage:

  1. Is true by default,
  2. prevents the client from fetching translations from the server (it apparently tries to only fetch them from local browser storage, no idea how would it become populated),
  3. isn't documented on http://jamuhl.github.com/i18next-node/ - one can discover what's going on and why client doesn't fetch translations only by using the browser's JavaScript debugger or by comparing own code with the sample at https://github.com/jamuhl/i18next-node/blob/d1f362435b25b389000b51797ffd5b1fea839d93/sample/index.jade (which, for unspecified reasons, has explicit useLocalStorage: false).

I don't know which those three is wrong, so am not providing a ready pull request; but it seems that this is a problem that needs addressing - with the defaults, client side stuff is nonfunctional.

Can i18next handle this case ?

Hi,

I have a special case where the fallback language won't always be the one specified during initialization. Let me explain :

It's 2 languages website, French and English. Language is passed in url at first position, using only the language code (not the country code). When there's no language in url, here's the scenario :

  • when i18next detect they're French (using cookie and http header), serve French. So basically it should be the same as having the fr in the url.
  • when i18next detect they're something else, serve English.
  • when 18next doesn't detect anything (is it possible), serve French or English, unsure yet.

Can you answer precisely please, especially regarding the last case for both fallback languages ? Thank in advance.

Infinite loop when browser language is set with Country-Code

I initialize i18next with these settings :

i18n.init({
  load: 'current',
  supportedLngs: ['en', 'fr'],
  detectLngFromPath: 0,
  fallbackLng: 'en',
  ignoreRoutes: ['img/', 'javascripts/', 'stylesheets/'],
  saveMissing: true,
  keyseparator: '::',
  nsseparator: ':::',
  debug: config.i18n.debug // true
});

So when my browser language is set to fr-FR I expect it to fallback on fr. Instead, when I visit localhost:someport/, I end up at localhost:someport/fr-FR/fr-FR/fr-FR/fr-FR/fr-FR/fr-FR/fr-FR/fr-FR/fr-FR/fr-FR/fr-FR/fr-FR/fr-FR/fr-FR/fr-FR/fr-FR/fr-FR/fr-FR/fr-FR/fr-FR/fr-FR, the browser tells me there's an infinite loop (both Chrome and Firefox), the debug output in the console shows :

currentLng set to: fr-FR
[ { [Error: ENOENT, open 'locales/fr-FR/translation.json']
    errno: 34,
    code: 'ENOENT',
    path: 'locales/fr-FR/translation.json' } ]
currentLng set to: fr-FR
currentLng set to: fr-FR
currentLng set to: fr-FR
# shortened, but there are around 40 of these

This happens only when I remove the cookie. When I have a proper cookie, i18next uses the cookie just fine and things work as expected. Will investigate

Check language on an jade template?

Hi

I have two bigger jade templates, that i want to include without a resourefile, like so:

if i18next.language == 'de'
  include inc/templ_de
else
  include inc/templ_en

is this possible ?

Thanks

few questions

Hello!

I am a beginner to i18next-node, so don't please be offended with my questions :)
So I have two questions:

  1. is it possible to set language in the init method once and for all, because currently I set in options lng : "en-US" and in can be changed for "en-CA" or "uk-UA" depending from witch computer I login my application. I have changed manually "detectLanguage" function in 18nextWrapper but I am afraid I missed something in existing options.
  2. how can I set translation language for each user individually. Let’s say, user has db property LNG and on each request to the server I have to use method setLng? or there is some better way to set language only for this request?

Thank you all

req.i18n has no method setLng in 1.5.13

I just upgraded to 1.5.13 from 1.5.5 and noticed that method req.i18n.setLng is no longer available. This seems to start from 1.5.7, is there a new way to set language for each request?

Gotcha: . in key

One of my keys in the language files has a . inside.

Eg.

{
  "errors": {
    "must contain only a-z . -": "måste innehålla enbart a-z . -"
  }
}

This makes the lookup failing:

t('errors.must contain only a-z . -') // => errors.must contain only a-z . -

This is because it thinks the . is a key delimiter.

Is there a way to make it work although a key contains a .?

saveMissing : true = SyntaxError: Unexpected end of input

If I set saveMissing : true when I try to run my app I'm getting this error:

SyntaxError: Unexpected end of input
    at Object.parse (native)
    at /home/panosru/domains/example.com/public_html/node_modules/i18next/lib/sync.js:76:31
    at [object Object].<anonymous> (fs.js:115:5)
    at [object Object].emit (events.js:64:17)
    at afterRead (fs.js:1112:12)
    at Object.wrapper [as oncomplete] (fs.js:254:17)

18 Mar 15:54:29 - [nodemon] app crashed - waiting for file changes before starting...

Key with `.` saved but without value

Reporting a strange behavior. I'm taking advantage of the saveMissing option (a bliss) to save key:value in my dictionary file. I just noticed that for the only key with . inside (like in t("my key."), it was saved like this in the json file : "my key":{}. No value, and the dot was stripped out of the key. Is it a bug ?

Complicated plurals don't work for me

I'm trying to get complicated plurals to work, here is a test code:

var i18next = require("i18next");

i18next.init({ fallbackLng: "en", debug: true }, function (t) {
    console.log("Doesn't work");
    console.log(i18next.t("key", { count: 0 }));
    console.log(i18next.t("key", { count: 1 }));
    console.log(i18next.t("key", { count: 2 }));
    console.log();
    console.log("Works!");
    console.log(i18next.t("simple", { count: 0 }));
    console.log(i18next.t("simple", { count: 1 }));
    console.log(i18next.t("simple", { count: 2 }));
});

Which produces the following output

currentLng set to: en
loaded file: locales/en/translation.json
Doesn't work
0 like
1 like
2 like

Works!
0 likes
1 like
2 likes

With this translation file:

{
    "key": "__count__ like",
    "key_plural_0": "No likes",
    "key_plural_2": "__count__ likes",

    "simple": "__count__ like",
    "simple_plural": "__count__ likes"
}

I've been trying to understand the code behind this, but I can't get it to work.

language detection and supported languages

Hello, I have a problem with language detection when "detectLngFromPath" init option is enabled. If the url includes a "language-segment" for a non supported (but "valid") language, i18next returns the "valid" language even if it's not supported by the application.

A new init option for setting all the supported languages could be useful here. For now I made this small change in "i18nextWrapper.js" - line 30:

if (lookUp && opts.supportedLangs.indexOf(lookUp) > -1) locale = part;

and I pass "supportedLangs = [...]" on initialization.

YAML support

I find YAML to be an excellent translation format since now you can send the translation files to translators and they don't need to know JSON to translate it.

Exit: Avsluta
Create: Skapa

All my translation files are in yaml and I use https://github.com/nodeca/js-yaml to load them in:

var translation = require('locales/en-US.yml')
translation.Exit // => Avsluta
translation.Create // => Skapa

Could YAML be supported out of the box so we can have our translation files in YAML instead of JSON?

Pluralization doesn't handle zero

When the 'count' option is 0 (zero), I get the translation for the singular form.
I.e. my translation.json fragment:

{
  "comment": "1 comment",
  "comment_plural": "__count__ comments"
}

my code fragment:

console.log(t('comment', { count: 1 })); // → 1 comment
console.log(t('comment', { count: 2 })); // → 2 comments
console.log(t('comment', { count: 0 })); // → 1 comment

I didn't found any special handling of zero counts. Am i doing something wrong?

error loading resourcefile

Hello, in my application I have this:

i18n.init({
    lng : 'el-GR'
  , fallbackLng : 'en-US'
  , resGetPath : $settings.paths.locales
  , resSetPath : $settings.paths.locales
});

my locales path is like this:

+- locales
+-- el-GR
+--- translation.json
+-- en-US
+--- translation.json

So why it asks for these:

error loading resourcefile: /home/rnd/domains/design.rnd/public_html/app-ui/apps/main/system/locales/el/translation.json
error loading resourcefile: /home/rnd/domains/design.rnd/public_html/app-ui/apps/main/system/locales/en-us/translation.json
error loading resourcefile: /home/rnd/domains/design.rnd/public_html/app-ui/apps/main/system/locales/en-us/translation.json
error loading resourcefile: /home/rnd/domains/design.rnd/public_html/app-ui/apps/main/system/locales/en-us/translation.json
error loading resourcefile: /home/rnd/domains/design.rnd/public_html/app-ui/apps/main/system/locales/en/translation.json
error loading resourcefile: /home/rnd/domains/design.rnd/public_html/app-ui/apps/main/system/locales/en/translation.json
error loading resourcefile: /home/rnd/domains/design.rnd/public_html/app-ui/apps/main/system/locales/en/translation.json

why except of el-GR and en-US I should have el and en and en-us (lowercase) and not el-gr (lowercase) isn't it possible to have just el-GR and en-US only, as they are the only ones defined?

I could understand maybe to have el and en folder but seriously I can't understand the use case of having en-us with lowercase too and not having el-gr with lowercase too, it seems like a tiny bug for me.

Thanks

Bug after 1.5.5 update

Hi,

First of all, amazing module, thanks for sharing it with the rest of us.
Now the "bug" (not sure if it is, i'm a node noob, so sorry if this is just something I missed):

(...)/node_modules/i18next/lib/dep/i18next-1.5.5.js:2071
                var parts = lng.split('-');

TypeError: Object  has no method 'split'
    at Object.pluralExtensions.setCurrentLng ((...)/node_modules/i18next/lib/dep/i18next-1.5.5.js:2071:33)
    at init ((...)/node_modules/i18next/lib/dep/i18next-1.5.5.js:524:26)
    at Object.i18n.init ((...)/node_modules/i18next/lib/i18next.js:53:9)
    at Object.<anonymous> ((...)/app.js:36:9)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.runMain (module.js:492:10)
    at process.startup.processNextTick.process._tickCallback (node.js:244:9)

Rolling back to 1.5.0 "solves" the issue. The error pops up right at server startup. Hope you can help me :)

cheers

resSetPath Setting

Why all new strings are saved to locales/dev/.... even if resSetPath is set like

resSetPath: 'locales/lng/new.ns.json'

?

Thanks.

Error with sessions ?

Hi

I have sometimes the following error with sessions:

TypeError: Cannot read property 'encrypted' of undefined
at Object.set (/app/node_modules/i18next/node_modules/cookies/lib/cookies.js:41:28)
at Object.persistCookie (/app/node_modules/i18next/lib/i18next.js:134:17)
at /app/node_modules/i18next/lib/i18next.js:51:18
at /app/node_modules/i18next/lib/dep/i18next-1.2.3.js:140:21

i use the following versions:

I've found this:

pillarjs/cookies@739d476

But does anyone know the reason of this ?

Thanks and greetings from switzerland ;)
Remo

$.i18n.setLng how should affect client-server behaviour?

I was wondering if $.i18n.setLng should affect client-server locale...

So if we take in consideration that @jamuhl accept the pull request where I pass httpOnly : false on the cookie.set then when we change the language using the ?setLng= it will affect both client and server but I'm wondering if $.i18n.setLng should work in the same way... I mean should we set the cookie value when we use $.i18n.setLng ? What do you think? Currently in order to change language "transparently" I use something like this:

$.get('/?setLng=el-GR', window.location.reload);

So the above do a simple thing, calls the root url with ?setLng=el-GR the request is done by ajax so the cookie is set transparently, and we reload the page as a callback, the next time page reloads will have the new locale set in cookie in order to be used from both client and server.

I was wondering if this: $.i18n.setLng('el-GR', window.location.reload); should have similar effect with previous code.

Thanks

PS: The reason I post this issue on i18next-node and not in i18next is because it is mostly related to client-server behaviour and not just client.

New translation isn't shown on the client side

I've been using i18next-node on the server side with great success. However on the client side, the translation isn't updated when I add new keys to the translation files. I'm guessing the reason is the browser caches the translation file, because all translations show up correctly when I clear browser cache. So I wonder if there's any way to tell the client to reload when there're updates in the translation files? If not, is it possible to prevent the client from caching the translation?

Thanks

Client-server shared resources

Hello, I tried to use $.i18n.t('creator.firstname'); in client-side but I got creator.firstname instead of the expected string.

the init method looks like this:

i18n.init({
    lng : 'el-GR'
  , fallbackLng : 'en-US'
  , resGetPath : $settings.paths.locales
  , resSetPath : $settings.paths.locales
  , dynamicLoad: true
});

$settings.paths.locales is set like this: path.normalize(__dirname + '/../locales/') + '__lng__/__ns__.json'

In my jade layout I have this: script(src='/i18next/i18next.js')

Thanks

Can't get translation working

I don't know why I can't get the translation working:

In my project folder I have:

server.js
locales/en-US/translation.json

translation.json:

{
  Exit: 'Avsluta'
}

server.js:

var i18n = require('i18next');

i18n.init({
  lng: 'en-US',
  debug: true
});

console.log(i18n.t('Exit'));

When I run server.js it prints out "Exit" and not the translation.

The debug info told me that the translation file was loaded.

But why isn't it translating?

Random double underscores `__` appear

For a reason I completely ignore and don't understand, i18next inserts __ when saving key to file. Basically I write some key in my template : t("Some text, may be long.") and i18next saves it on disc like this : "Some text, __may be long.": "Some text, __may be long.". In my case it only appeared after commas, but as it's not systematic and almost rare I can't say it's related. I didn't investigate in code.

Access a translation in a language different from the current

Hello, and thanks for sharing this great module! Is there any way to access a key's translation, in a language different from the current? For example if the user session's language is el-GR, a language selector could have a link with a title "View content in English" (a phrase not in current language). How can I access this phrase's translation with the t() helper function in a jade template?

Problem with plural forms in french

Hi,

It seems that the French plural option is not working properly as I have to put keys with a "_plural_1" suffixe to make it look as a plural version (instead of just "_plural").

It may be linked to the way the "fr" rule is written, which is slightly different from the "en" one (which is working) :

        "fr": {
            "name": "French", 
            "numbers": [
                1, 
                2
            ], 
            "plurals": function(n) { return Number(n > 1); }
        }, 

vs.

        "en": {
            "name": "English", 
            "numbers": [
                2, 
                1
            ], 
            "plurals": function(n) { return Number(n != 1); }
        }, 

Also, when I look at your code in the i18next lib, I found these lines quite strange in the _translate function :

        if (pluralExtension >= 0) { 
            pluralKey = pluralKey + '_' + pluralExtension; 
        } else if (pluralExtension === 1) {
            pluralKey = ns + ':' + key; // singular
        }

The second part of the if statement will never be called, right ? :-)

When I use the "_plural_1" suffixe workaround, it is working though, but I just would like you to be aware of this issue.

Thanks to your module, we have finally put our website into production a few days ago at http://www.omiracle.fr, in French and in English as well. We've both used the client version and the server version of i18next, which is really working great !

(For information, our website is a "social" real estate listing service which helps users create/find a flatshare in Paris and its suburbs (at first, we hope to be able to add other cities and renting/selling as well), using social networks to get common friends and points of interest you may have with your future flatmates but also to communicate about your listings to all your relations in order to increase the chances you find someone interested)

Ignore language given in headers

Hey,

I'm trying to use i18next to do translations on my node project, that's suposed to support english and spanish (en-UK and es-ES). My config is the following:

i18next.init({ 
    ns: { namespaces: ["front", "manager", "admin", "main"], defaultNs: "main"},
    debug: true, 
    resSetPath: "locales/__lng__/__ns__.json",
    languages: ["es-ES", "en-UK"],
    fallbackLng: "es-ES"
});

My problem: my headers say accepted languages are "en-US, en", which makes i18next use en-US. I want to ignore the headers, and just fallback to es-ES if (and only if) no cookie or path info is given. I've tried a few config schemas, but no luck so far. Any idea on how I can achieve this?

cheers

Redis Backend

Would like to be able to store translations in redis

Clients may not get their pages rendered in the correct language

I've been using i18next-node for quite a while yet and I've been facing a synchronization issue when using it from different clients. I'll try to explain it as clearly as possible as synchronization issues are often hard to explain (and to understand).

Take two clients of a website. Client A is using Firefox and is connecting to a node server with English as chosen language, which will be put inside its cookies. Client B is under Chrome and has chosen French as its preferred language, which will also be put in its cookies.

The two clients then make requests to the server for the website home page which is rendered using a template module such as jade. As i18next is well integrated with node, express and jade templates, we can use the translate function inside the home page jade template to get words transcription. When requests are made seperately by the two clients, it is working well, client A has its home page in English whereas client B has its own in French. Good.

The issue is coming when the two clients make their requests at the same time (to get to it, make a F5 refresh in Firefox and click on the refresh button in Chrome at the same time, with both browser windows side-to-side opened). Suppose you have some asynchronous work in the home page GET route, for example data retrieval from a database, it will lead to the treatment of the two requests at the same time (as it is the core principle of node to authorize a second request to be treated when another one is making some IOs with the outside world). In that case, you may come up with two home pages in English or in French so one client may not be very happy :-).

I've been digging into i18next code and I've found that the problem is coming from the fact that it is the same i18n object that is shared between user requests so that if request A changes the i18n language into English and request B is treated before request A has rendered its content, request B will change i18n language to French and then both pages (A and B) will be rendered in French.

I think you should not use express locals as static helpers but instead use them with the request locale as parameter to avoid this issue (dynamic helper in express 2.x). I've managed to handle it by overriding the "t" local to the following function and it's correcting the issue :

t: function(req, res) {     return function(key, options) {         options = options || {};         options.lng = req.lng;         return req.i18n.t(key, options);     }; } What do you think of that ? Do you agree ? Or have I done something wrong using i18next-node ?

Thanks you.

Fallback language option, specifically for enabled "detectLngFromPath" option.

Hello, the "detectLngFromPath" option is a great future, but it would be nice if a fallback language (the same with "fallbackLng" or not) could be defined on initialization, specifically for that option. This is useful in cases where the URLs in the application's default language do not have a language URL segment. For example:

www.example.com
www.example.com/es/
or
www.example.com/examples
www.example.com/es/ejemplos

For now I made a quick change in "i18nextWrapper.js":

var detectLanguage = function (req, res) {
    // ...
    if (opts.detectLngFromPath !== false) {
        var parts = req.originalUrl.split('/');
        if (parts.length > opts.detectLngFromPath) {
            var part = parts[opts.detectLngFromPath + 1];
            var lookUp = wrapper.pluralExtensions.rules[part.split('-')[0]];
            if (lookUp) {
                locale = part;
            } else {
                locale = opts.fallbackLng;
            }
        } else {
            locale = opts.fallbackLng;
        }
    }
    // ...
};

Using i18next-node with moment.js

Does anyone know a way to sync the language selection between i18next and moment.js? I mean something like:

app.locals({
  format_date: function(val) {
    moment.lang(i18next.lng());
    return moment(val);
  }
});

It should be automatic switch the language of moment.js when i18n switch to a new language.

Thanks

How to use i18next-node indeed in project?

Question1:
How do I include i18next variable in server side program. likes:

res.render('index',{
title: t('app.example.title1'),
flash: t('app.example.flash-message')
}

Question2:
How do I set my forced locale?
Whatever the client-locale set, just force to fr-FR?

Question3:
In jade, just like: h1 t('app.example.title') ?

Thanks

TypeError: Cannot read property 'translation' of undefined

I initialize i18next with the following options:

i18next.init
  saveMissing: true
  debug: true
  load: 'unspecific'
  useCookie: false

This is output of simple express server:

currentLng set to: dev
Express server listening on port 3000
loaded file: locales/dev/translation.json
currentLng set to: ru
loaded file: locales/ru/translation.json
req.locale ru-RU

req.locale is log of req.locale variable in route

But I got an error about trying to save the missing key to locales/ru-RU/translation.json

TypeError: Cannot read property 'translation' of undefined
    at /home/mahnunchik/nodejs/blade_i18next/views/index.blade:6:3
    at Object.module.exports.postMissing (/home/mahnunchik/nodejs/blade_i18next/node_modules/i18next/lib/filesync.js:30:39)
    at _translate (/home/mahnunchik/nodejs/blade_i18next/node_modules/i18next/lib/dep/i18next-1.5.10.js:886:22)
    at Object.translate (/home/mahnunchik/nodejs/blade_i18next/node_modules/i18next/lib/dep/i18next-1.5.10.js:781:16)
    at Object.i18n.handle.t (/home/mahnunchik/nodejs/blade_i18next/node_modules/i18next/lib/i18next.js:84:25)
    at eval (eval at <anonymous> (/home/mahnunchik/nodejs/blade_i18next/node_modules/blade/lib/compiler.js:148:23))
    at Object.runtime.blockDef (/home/mahnunchik/nodejs/blade_i18next/node_modules/blade/lib/runtime.js:580:9)
    at Function.eval [as template] (eval at <anonymous> (/home/mahnunchik/nodejs/blade_i18next/node_modules/blade/lib/compiler.js:148:23))
    at Compiler.compile.wrapper (/home/mahnunchik/nodejs/blade_i18next/node_modules/blade/lib/compiler.js:142:12)
    at /home/mahnunchik/nodejs/blade_i18next/node_modules/blade/lib/blade.js:83:3
    at /home/mahnunchik/nodejs/blade_i18next/node_modules/blade/lib/blade.js:44:4

This is wrong behavior if I want to use only the language code without the country code.

Accessing the parsed language objects?

I need to generate a list of languages in my HTML to let the users specify which language to use.

Instead of reading in all of the languages (language.json) myself I thought could use the language objects that i18n has loaded in so that I don't have duplication in memory.

Since I have this configuration:

preload: ['en-US', 'da-DK', 'sv-SE']

I thought i18n would keep an object (it's an object right?) with all the parsed languages in memory.

Is there a way to access this object from i18n (in)officially?

"returnObjectTrees" returns unexpected results

Hello, I have a problem with "returnObjectTrees" option. Below is a sample "translation-example.json" file:

{
    "exampleTranslations": {
        "translationKeyA": "exampleA",
        "translationKeyB": "exampleB",
        "translationKeyC": "exampleC"
    }
}

When I call

req.i18n.t('translation-example:exampleTranslations', { 'returnObjectTrees': true })

it returns this:

{
    'translationKeyA': 'exampleTranslations:translationKeyA',
    'translationKeyB': 'exampleTranslations:translationKeyB',
    'translationKeyC': 'exampleTranslations:translationKeyC'
}

Is it a problem with namespaces?

Support for ejs

Is the template engine ejs not supported?

I get:

t is not defined

when using it inside an ejs template.

If it's not supported, could support be added?

BTW: I'm using Express 3.

Plural form for 0

Reading the docs, I see that the plural form is used when the __count__ is 0. Really ? Is it a bug or is it English-related ?

MongoDB backend does not support username and password

Hi,

Your work here is great but I encountered an issue when putting it in production. I'm using i18next server-side and client-side as well as a mongo-db backend for the server-side version. However, it failed working because in production there are username and password parameters to feed to the authenticate function before getting my collections back and using them.

To help me on that, I've just added username and password to the options parameter of the connect function in i18next-mongodb module. Then, in the connect function, I use these to handle authentication to database :

self.isConnected = true;
self.client = client;

if (options.username && options.password) {
    client.authenticate(options.username, options.password, function() {
        self.resources = new mongo.Collection(client, options.resCollectionName);
        if (callback) callback(null, self);
    });
} else {
    self.resources = new mongo.Collection(client, options.resCollectionName);
    if (callback) callback(null, self);
} 

It would be great if you could add this for one of your future version of i18next-mongodb !

Whatever you choose, it may help some people to understand why their access to their mongo-db resources is failing.

The language detection cookie name could be customizable

The query string is already customizable, could the cookie name be customizable as well?

         if (!locale && opts.useCookie) {
             cookies = new Cookies(req, res);
             locale = cookies.get(opts.detectLngCookie);
         }

I'm sorry not to include a pull request, but I couldn't out figure how to do it.

i18n.serveMissingKeyRoute causes error upon client ajax callback

Due to i18next client defines the ajax request as a json dataType in the postMissing function inside the sync object, the serveMissingKeyRoute route in the server should response with a json string. If the response is not the same dataType as defined in the ajax request (currently it is doing a res.send("OK")) an error callback is called upon response and so no update over the resStore is being made even when the request really succeds.

Dynamic reloading of files when modified

What are your thoughts on a watcher mechanism and reloading of modified translation files?

It's not that they are changed often, but if they are then it avoids needing to restart the process (which could be a production web server).

?setLng= not working

I tried to use example.com/?setLng=el-GR or en-US or any other and it didn't worked, it still read browser's locale.

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.