Basic translator using Vanilla JavaScript

5 replies
  1. japanfever
    japanfever says:

    are you always loading the texts of all the languages? you should use ajax to load only the file with the user’s language

    • Génesis
      Génesis says:

      It depends on the app. Imagine you have a SPA, a phone app where you don’t want to waste your Internet connection (monthly data bandwidth) or even you don’t have Internet access and want to switch between a couple of languages. You have plenty of room in your local storage for those files. For example in the new app I’m working on there are 5 languages/files with 500 lines each and in many cases when the user starts using the app for the first time there is not Internet: outskirts of the city, underground, etc.

  2. japanfever
    japanfever says:

    i mean loading the files in the browser internal memory, not loading them from internet. you are loading all the files 5?, when you only need one. i inform you that ajax can also be used with local files in a mobile application without internet. once you know the user’s language, you only have to get a file with its translation, and not 4 useless arrays more from 4 useless files. the page load will be faster and less ram will be spent on the mobile. delete the lines script src=”language.en.js” and script src=”language.fr.js” from html and use a dynamic load in javascript. come on noob, you can do it! hah

    • Génesis
      Génesis says:

      Ok, now I see your point! You are right, we do it that way, if we have one or two languages we use it like in the previous example, with more than two languages we load just the specific file. Anyway my example is for a basic understanding (people use libraries for everything). Well, maybe I can load the internal file in a “language” variable and update the gist. A really pity that we cannot use Fetch API in phone devices for that. Nice to see that your English is improving a lot 😛

Comments are closed.