React-i18next: Support for .yaml file type for language

Created on 30 Aug 2020  路  4Comments  路  Source: i18next/react-i18next

馃殌 Feature Proposal

Motivation

  • It's a little bit difficult to manage the .json file type for language, Is there a way to use the .yaml file type

Please outline the motivation for the proposal.

Example

Instead of translation.json we could use translation.yaml

Most helpful comment

okay! Thanks @jamuhl it worked. Just need to add more code as below

Reference for other's

import yaml from 'js-yaml';

backend: {
      loadPath: '/locales/{{lng}}/{{ns}}.yaml',
      parse: function(data) { return yaml.load(data) },
    },

All 4 comments

depends on the backend loading...https://github.com/i18next/i18next-http-backend#backend-options -> check the parse option (parse yaml)

Thanks, @jamuhl for responding but looks like file with .yaml type is not supporting
for example, I'm trying the below code but it's not working.

import i18n from 'i18next';
import Backend from 'i18next-http-backend';
import LanguageDetector from 'i18next-browser-languagedetector';
import { initReactI18next } from 'react-i18next';

const languages = ['en'];
i18n
  .use(Backend)
  .use(LanguageDetector)
  .use(initReactI18next)
  .init({
    fallbackLng: 'en',
    debug: true,
    whitelist: languages,
    backend: {
      loadPath: '/locales/{{lng}}/{{ns}}.yaml',
    },
    interpolation: {
      escapeValue: false, // not needed for react as it escapes by default
    },
  });

export default i18n;

In place of .yaml if i put .json then it is working :-1:

like said...have a look at parse option...just changing the loadPath is not enough -> you will have to define how to parse yaml to js object

okay! Thanks @jamuhl it worked. Just need to add more code as below

Reference for other's

import yaml from 'js-yaml';

backend: {
      loadPath: '/locales/{{lng}}/{{ns}}.yaml',
      parse: function(data) { return yaml.load(data) },
    },
Was this page helpful?
0 / 5 - 0 ratings

Related issues

a-barbieri picture a-barbieri  路  4Comments

pwiszowaty0 picture pwiszowaty0  路  4Comments

tankpower1 picture tankpower1  路  3Comments

leandrocamacho picture leandrocamacho  路  4Comments

Jessidhia picture Jessidhia  路  4Comments