Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting i18next translator Missing key

Tags:

This is my first time with i18next and I have no idea how to make it work. (it seems like the documentation is incomplete to me) This is my HTML code with i18next

<html>   
  <head>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/i18next/4.0.0/i18next.min.js" ></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-i18next/1.1.0/jquery-i18next.min.js"></script>
    <script src="/i18nextXHRBackend.min.js"></script>   
  </head>

  <body>
      <div id="test">
        <a data-i18n="Hello"></a>
        <div data-i18n="World"></div>
      </div>

      <script>
        i18next
            .init({
                "debug": true,
                "lng": "en",
                "ns": [
                  "translation"
                ],
                "fallbackLng": false,
                "keySeparator": false,
                "nsSeparator": false,
                resources: {
                  "backend": {
                    "loadPath": "locales/{{lng}}/{{ns}}.json"
                  }
                }
              }, function(err, t) {
               jqueryI18next.init(i18next, $);
               $('#test').localize();
             });
      </script>
  </body>  
</html>

And this is my JSON:

{ "Hello" : "Hello in english", "World" : "World in english" }

Nothing display in my page, In console I have got this

i18next::translator: missingKey en translation Hello

i18next::translator: missingKey en translation World 

Am I missing anything?

like image 455
Aditya Tomar Avatar asked Mar 02 '17 14:03

Aditya Tomar


People also ask

How do I use i18next in react native?

Basic usage import React from 'react' import { Text } from 'react-native' import { useTranslation } from 'react-i18next' const Component: React. FC = () => { const { t } = useTranslation() return <Text>{t('demoScope. title')}</Text> // -> "i18next is Great!" }

What is i18next HTTP backend?

i18next-http-backend is a backend layer for i18next using in Node. js, in the browser and for Deno.

What is i18next parser?

Scan your code, extract translation keys/values, and merge them into i18n resource files. ​i18next-parser​ A simple command line and gulp plugin that lets you parse your code and extract the translations keys in it.


1 Answers

if you get missing that's a sign for the translations in your json file where not loaded at all.

there should be warnings about backend not able to load those in the console.

make sure: locales/en/translation.json is accessible - or fix the path accordingly

like image 52
jamuhl Avatar answered Sep 23 '22 10:09

jamuhl