Search code examples
htmlmultilingual

Best solutions for multi-language website


I'm currently having a regular HTML website in multiple languages. I've tried something with PHP, but that didn't turned out very well. What I need is a Multi language site without: - Subdomains (like en.domain.tld) - Paths (like domain.tld/en)

What I do need: - Languages that are stored in sessions/cookies - Languages which can be used around the whole site (with one place to store the language files, if that's necessary) - Preferably without visible indications in the URL (like ?lang=en).

A bit like how Google does it, because I also have multiple TLDs, so the user shouldn't be required to change their language by visiting another domain like .de, if they set their language to English from the .com site.

What is the best solution for this? I'm also very new to making websites, so that's why I'm asking.


Solution

  • What i prefer to do is

    1. Create a localization directory at the top level of your app

    index.html

    app.js

    localization/

    1. Inside localization directory create two files

    web-en.json

    {
    "title":"Hello world",
    "desc":"languages are fun"
    }
    

    web-es.json

    {
    "title":"Hola Mundo",
    "desc":"idiomas son divertidos"
    }
    
    1. Install this library "jquery-localize": "https://github.com/coderifous/jquery-localize.git"

    bower install jquery-localize

    1. Include the library

    2. Add the attributes to your HTML tags

      Hello World will go here Translated desc will replace this text
    3. Call the library onReady

    $(function(){ $("[data-localize]").localize("localization/web"); };