wyattis / babel-plugin-content-transformer

MIT License
1 stars 0 forks source link

React-native. Changes in yaml files displays only after restart metro server. #4

Open stasmotorny opened 2 years ago

stasmotorny commented 2 years ago

Hi guys. I am using your library to use yaml files instead of json in react-i18next localisation library. It works fine but there is one issue: when i change some translation in .yml file the changes displays only after I restart metro server. Reload also doesn't works, I see no changes after I pressed 'r' to reload server. To see changes I need to stop and after that run server again. My babel.config.js is

module.exports = function (api) {
  const presets = [['module:metro-react-native-babel-preset']]
  const plugins = [
    ['module-resolver', {
      root: ['./'],
      extensions: ['.ios.js', '.android.js', '.js', '.ts', '.tsx', '.json'],
      alias: {
        '@bluecentury': './src',
      }
    }],
    ['module:react-native-dotenv', {
      'moduleName': '@vemasys/env',
    }],
    ['react-native-reanimated/plugin'],
    ['content-transformer', {
      transformers: [{
        file: /\.ya?ml$/,
        format: 'yaml'
      }]
    }]
  ]
  api.cache(false)
  return {
    presets,
    plugins
  }
}

my i18n.ts is

import i18n from 'i18next'
import {initReactI18next} from 'react-i18next'
import translationEN from './enyaml.yml'
// import translationEN from './en.json'

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

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

When I'm using en.json everything works fine.

wyattis commented 1 year ago

Can you post your metro config as well?

wcandillon commented 1 year ago

I would also be interested to know if there is a workaround for this issue

gongzhxu commented 1 year ago

+1

if anyone can help