Search code examples
javascriptgoogle-chromegoogle-chrome-extensionchromium

Is there any way to set a current locale?


I was trying to use i18n for an extension but I don't want to use the browser language, instead I want to use the website language. The problem isn't how to get the website language because I already know how to get it, the problem is that when I use getMessage it returns a string with the current language (browser language) and in the documentation they doesn't mention a way to send a locale so it returns the actual website language.


Solution

  • If your purpose is to create a context script based on the language of the website you are visiting, I don't think "i18n" can help you. But you can build a personalized internationalization system. First retrieve the language of the website and then go to read (with fetch or XHR commands) the contents of the file relating to that language (which could have a JSON structure similar to that used by the i18n API or customized according to your needs).