Code Monkey home page Code Monkey logo

Comments (2)

tfrommen avatar tfrommen commented on May 5, 2024

No problem, I will update the German translations in a second.

However, I would strongly suggest to fully separate any (to-be-translated) strings from the rest of the app, and thus have only one index.html that reads the user's language and then uses the according strings (with a fallback to English for any missing translation). Otherwise, keeping the translations up-ot-date is a very tedious task. For instance, adding a new language would require updating also all the other index.html files. Having a separate file (e.g., strings.js, or even strings.json) and then reading the according string is, in my opinion, the way to go.

var strings = {
    game: {
        level1: {
            en: '...',
            de: '...',
        }
    },
    messages: {
        warningReset: {
            en: '...',
            de: '...',
        }
    }
};

var getString = function( lang, id ) {
    var properties = id.split( '.' ),
        property,
        value = strings;

    while( properties.length ) {
        property = properties.shift();

        if ( ! value.property ) {
            return 'return empty string or something else here';
        }

        value = value.property;
    }

    if ( value.lang ) {
        return value.lang;
    } else if( value.en ) {
        return value.en;
    } else {
        return 'same error string from above or so...';
    }
};

Note this is just a quick write-up. Please don't take it as-is. :)

from flexboxfroggy.

thomaspark avatar thomaspark commented on May 5, 2024

Thanks @tfrommen, the way languages are handled is definitely due for a refactor. Your approach looks good to me, though I might prefer to use a query string than automatically detect the user language. I'll merge your changes for now and hopefully get to that soon.

from flexboxfroggy.

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.