N
N
nepster-web2015-05-05 03:53:20
Internationalization and localization
nepster-web, 2015-05-05 03:53:20

Is it worth splitting translations between programming languages?

I am developing a multilingual project and came across a situation where a lot of js scripts are used with their own small phrases.
Initially, all translations are stored in the database, but sometimes there are situations when you just need to show a phrase that is packed in a js file.
Hence the question:
What is better, to store separate js translation files (ru.js, en.js, etc.) or register a php file:
<script src="lang.php"></script>
in which to generate a js object with the necessary phrases in the desired language?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
6
65536, 2015-05-05
@65536

multilingualism eliminates hardcoding of phrases anywhere
you can create an object

var dictonary = {
    ru: {
        word1: "фраза 1",
        word2: "фраза 2"
    },
    en: {
        word1: "word 1",
        word2: "word 2"
    }
}

also somewhere globally declare a variable that contains the current language.
in your file, replace all phrases with the corresponding elements of the object
...dictonary[lang]['word2']...

I
index0h, 2015-05-05
@index0h

Cheapest: js/php file generator on request, or database change. In the code, you already include the one you need, whether it's ru.php or uk.js

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question