Giter VIP home page Giter VIP logo

Comments (9)

jamuhl avatar jamuhl commented on August 15, 2024 1

for development you could turn off fallback lookup i18n.init({ fallbackLng: false });

http://i18next.com/pages/doc_init.html

from i18next-node.

kktos avatar kktos commented on August 15, 2024

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.

jamuhl avatar jamuhl commented on August 15, 2024

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.

kktos avatar kktos commented on August 15, 2024

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.

jamuhl avatar jamuhl commented on August 15, 2024

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.

kktos avatar kktos commented on August 15, 2024

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.

jamuhl avatar jamuhl commented on August 15, 2024

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.

kktos avatar kktos commented on August 15, 2024

Excellent. works like a charm ;)
kudos to you.
Devs are now happy :).

from i18next-node.

jamuhl avatar jamuhl commented on August 15, 2024

will be added to v1.5.14 (1.5.9 client) -> should come today or tomorrow

from i18next-node.

Related Issues (20)

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.