skip to Main Content

I can’t make i18next use yaml files for translation. Everything works fine with .json, but not with .yml I have no errors just no translation.

My i18n.ts is:

import i18n from 'i18next'
import {initReactI18next} from 'react-i18next'

const translation = require('./enyaml.yml')

export const resources = {
  en: {
    translation,
  },
}

i18n.use(initReactI18next).init({
  resources,
  lng: 'en',
  fallbackLng: 'en',
  interpolation: {
    escapeValue: false,
  },
})

As I can see this is some trouble with import or support of yaml files. Really appreciate any advices.

2

Answers


  1. Chosen as BEST ANSWER

    To use yaml files in react-native I installed babel-plugin-content-transformer and add in babel.config.js in plugins

    ['content-transformer', {
      transformers: [{
        file: /.ya?ml$/,
        format: 'yaml'
      }]
    }]
    

    Now it works fine and I can use yaml files in my application. But there's new issue application displays .yml file changes only after server restart.


  2. I have used i18n for multiple language select.
    In assets/lang/en.json,…/hi.json,…/ma.json,…/te.json Based on user selection u need to pass the json lang txt.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search