JavaScript Internationalization and Localization of Strings

Поделиться
HTML-код
  • Опубликовано: 3 фев 2025

Комментарии • 9

  • @SvendErix
    @SvendErix 5 лет назад +1

    Just a detail: You use "dk" as language code. "dk" is actually the country code. The language code is "da"

  • @i_mnikhil
    @i_mnikhil 3 года назад

    hi steve, i am technical SEO analyst, i just want know! if i apply this on website does it translate the website automatically according to their locale wherever the website open!

  • @farhankhan394
    @farhankhan394 6 лет назад

    Are you there?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  6 лет назад +2

      Quite often yes.

    • @farhankhan394
      @farhankhan394 6 лет назад

      @@SteveGriffith-Prof3ssorSt3v3 how should i localize my website contents, depend upon user country base means i want auto localized,, is that really matter to change one by one words?

    • @farhankhan394
      @farhankhan394 6 лет назад

      @@SteveGriffith-Prof3ssorSt3v3 i want you to add easy way to understand it if possible or i can show you mu website link amd it's about events l.

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  6 лет назад +1

      It is not a quick simple thing and there are many ways to do it. If you base it on the person's ip address then you need to use an API or server-side reference for converting ip addresses to locations. These are not very accurate. VPNs will change a person's location. It's better if you use the locale of the person's computer. Use the `navigator.language` property to see what language they are using.
      Then you need to have copies of the content for every page in every language stored somewhere. You have to do the translations. There is no automated tool for this.
      You could have all the content for each language on different html pages and redirect the user to the page for the right language OR you can put all the content inside the same page and then you could use JavaScript and/or CSS to show and hide the appropriate content based on the value of the lang attributes in the HTML.
      That's for the text content translated.
      Then there is also the question of handling the localization for time, currency and text direction. That is a mixture of JavaScript and CSS. The video above talks about how you can localize time and currency. Text direction is a CSS thing that can be tied to the lang attributes.