Comments (9)
for development you could turn off fallback lookup i18n.init({ fallbackLng: false });
http://i18next.com/pages/doc_init.html
from i18next-node.
yep, that's what I did:
var options= {
lng: lang,
resGetPath: '/locales/resources.json?lng=lng&ns=ns',
dynamicLoad: true,
fallbackLng: false,
debug: true,
defaultValue: null
};
but the result is the same. :(
from i18next-node.
try setting i18n.init({ load: 'current' });
else i have no clue...should work - need to add some tests if this one doesn't do the trick.
from i18next-node.
same, I'm afraid.
Look at the source : i18next-node/lib/dep/i18next-1.5.8.js, line 617.
you set up the default value as the elem.text() when it would have been nice to have the key instead, at least in DEV env.
cheers.
from i18next-node.
ok...i see. Wasn't aware you're using the jquery function (as i personally never use it - using t function with template engine). I implemented this for nice defaultValues when you're using the postMissingKeys feature.
Only way to change this behaviour would be to add another configuration option for this. So the function don't grab defaultValues from content.
If you really need this behaviour i could add this to the next release?
from i18next-node.
would be great, yes. Meanwhile, I'll hack the source to have it.
so let's say the option for i18n.init is defaultValues: false.
Could u give me a hint on how to pass to down to the function parse, please ?
ps: not using it in the template as I don't want to request all my templates from the client.
from i18next-node.
option would be: defaultValueFromContent: false
as it's only an issue on the jquery function not on the pure t function.
pass options via $('.mySelector').i18n(options)
-> will be passed to localize and from there to parse.
Best would be you build your own version of i18next clientscript. And change there:
function addJqueryFunct() {
// $.t shortcut
$.t = $.t || translate;
function parse(ele, key, options) {
if (key.length === 0) return;
var attr = 'text';
if (key.indexOf('[') === 0) {
var parts = key.split(']');
key = parts[1];
attr = parts[0].substr(1, parts[0].length-1);
}
if (key.indexOf(';') === key.length-1) {
key = key.substr(0, key.length-2);
}
var optionsToUse;
if (attr === 'html') {
optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options;
ele.html($.t(key, optionsToUse));
}
else if (attr === 'text') {
optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options;
ele.text($.t(key, optionsToUse));
} else {
optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options;
ele.attr(attr, $.t(key, optionsToUse));
}
}
function localize(ele, options) {
var key = ele.attr('data-i18n');
if (!key) return;
if (!options && o.useDataAttrOptions === true) {
options = ele.data("i18n-options");
}
options = options || {};
if (key.indexOf(';') <= key.length-1) {
var keys = key.split(';');
$.each(keys, function(m, k) {
parse(ele, k, options);
});
} else {
parse(ele, k, options);
}
if (o.useDataAttrOptions === true) ele.data("i18n-options", options);
}
// fn
$.fn.i18n = function (options) {
return this.each(function() {
// localize element itself
localize($(this), options);
// localize childs
var elements = $(this).find('[data-i18n]');
elements.each(function() {
localize($(this), options);
});
});
};
}
from i18next-node.
Excellent. works like a charm ;)
kudos to you.
Devs are now happy :).
from i18next-node.
will be added to v1.5.14 (1.5.9 client) -> should come today or tomorrow
from i18next-node.
Related Issues (20)
- i18next multiple json packages HOT 2
- Multiple handler on addRoute function HOT 3
- remoteSync don't write empty resource to store if remote is unavaiable
- Semvar violations HOT 2
- How to use variables with handlebars HOT 10
- remoteSync: saveMissing use resSetPath, not resPostPath HOT 3
- document webtranslate path options HOT 1
- document t helper
- Cannot read property '_translationTable' of undefined - i18next on OSX and docker HOT 2
- MongoDB backend fails to initialize HOT 6
- How do I create custom detectLanguage function\middleware? HOT 2
- Error when trying to pluralise HOT 4
- Dynamic routes render on any URL HOT 11
- Dinamically add new namespace? HOT 2
- Question: what is the best practice for i18next-node locales? HOT 9
- [same project?] Some pages down HOT 2
- README clarification HOT 1
- t is not a function HOT 8
- saveMissingTo: "all" does not save missing translation in all languages files
- Dynamic update app language in React Native using i18next HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from i18next-node.