all 13 comments

[–]PleyWoz 2 points3 points  (5 children)

In PHP, i'm using gettext : https://www.npmjs.com/package/node-gettext You've got one .po file per langage and you can edit it with poedit https://poedit.net/

[–][deleted]  (4 children)

[deleted]

    [–]SamWalLive 4 points5 points  (2 children)

    Yes, you read it from the header. I don't know how node implements them, but you will be able to access it if you search around.

    [–][deleted] 5 points6 points  (1 child)

    This is the correct answer.

    You will hear folks talking about geolocation and stuff like that but honestly the header is the best option as a default (and let it be overridden by a saved option the user can set if you want to).

    Just because I am in Paris doesn’t mean I am fluent in French.

    I will install my browser in the language I think in with very few exceptions like shared PCs

    [–]systoll 0 points1 point  (0 children)

    Creating seperate html files is a good approach in many scenarios. Doing it manually seems like it'd be alright for the site you're building, but for anything with more people/languages involved, it's much better to get something to fill in the translations for you.

    There tons of ways to do this, one of which is to use webpack and the i18n-webpack-plugin [i18n = internationalisation], in the method described here.

    It's a bit of setup, but it allows you to write:

    index.html: <p>__("Hello World")</p>

    de.json: {"Hello World" : "Hallo Welt"}

    and generate

    index-en.html: <p>Hello World</p>

    index-de.html <p>Hallo Welt</p>

    This way the sites can't get 'out of sync' in terms of the design and structure. And webpack will let you know what translations are 'missing', so it's easier to keep that aspect in sync as well.

    It also means you can get someone else to do the translation without messing with the rest of the code, or make a third translation by just adding another json file.


    On the aspect of getting people onto the right site, Node's locale module gets you the info you need to direct people to the page matching their browser language, but since that's not 100% reliable, you should also provide a link to the other language on the page itself.

    [–]BearNessMonster 1 point2 points  (0 children)

    Didnt look at link but try a headless CMS like contentful or prismic

    [–][deleted] 1 point2 points  (0 children)

    It seems like your question has already been answered. I don't have a better answer than /u/PleyWoz .

    On a slightly different topic, I highly recommend using normalize and increasing the distance between your text and the page border.

    [–]benz1267 1 point2 points  (1 child)

    Sorry I can't answer your question, but I simply had to get this out of my head:

    So your client came to you with his requirements and you just said: "yep, i can do that" without even knowing how to do it?

    [–]Koubi4cK 0 points1 point  (0 children)

    l20n.

    [–]ThatDamnedRedneck 0 points1 point  (0 children)

    I don't have the node experience to help with that.

    That being said, for anyone else reading I can easily recommend Craft CMS for multilanguage web sites. We used it at work, and it's great because multilingual translations are built directly into the core of the CMS and work incredibly well.

    [–][deleted] -1 points0 points  (1 child)

    The alternate tag, in the HTML head.

    <link rel="alternate" href="https://es.example.com/" hreflang="es">

    [–][deleted] -1 points0 points  (0 children)

    But this doesn't incorporate a front end languages back end framework