Replies: 3 comments 6 replies
-
You can refer to this repo I put together that allows you to work with i18n on both next and expo, and share components. |
Beta Was this translation helpful? Give feedback.
-
Here is how I set up the internalization for Solito: In - /locales
- en
- common.json
- tr
- common.json
- index.js
- index.web.js Setup Files/packages/app/utils/localization/index.ts (mobile)import * as Localization from 'expo-localization'
import { I18n } from 'i18n-js'
import en from './locales/en/common.json'
import tr from './locales/tr/common.json'
export const i18n = new I18n({
en: en,
ja: tr,
})
i18n.locale = Localization.locale
i18n.defaultLocale = 'en'
i18n.enableFallback = true
export const useTranslation = (file: string) => {
const changeLanguage = () => {
// TODO
}
return {
t: i18n.t,
i18n,
language: i18n.locale,
changeLanguage,
}
} /packages/app/utils/localization/index.web.ts (web)import { i18n, useTranslation as useNextTranslation } from 'next-i18next'
import { useRouter as useNextRouter } from 'next/router'
import { useRouter } from 'solito/router'
export const useTranslation = (file: string) => {
const { push } = useRouter()
const { t, i18n } = useNextTranslation(file)
const { pathname, asPath } = useNextRouter()
const changeTo = i18n.language === 'en' ? '' : 'en'
const changeLanguage = () => {
push(`/${changeTo}${pathname}`, `/${changeTo}${asPath}`, {
locale: false,
})
}
return {
t,
i18n: i18n,
language: i18n.language,
changeLanguage,
}
} Configs/app/next/next-i18next.configconst path = require('path')
module.exports = {
i18n: {
defaultLocale: 'tr',
locales: ['en', 'tr'],
localeDetection: false,
localePath: path.resolve('../../packages/app/utils/localization/locales'),
},
} /app/next/next.config.jsconst { i18n } = require('./next-i18next.config')
/** @type {import('next').NexConfig} */
const nextConfig = {
// 👇🏼
i18n,
reactStrictMode: true,
swcMinify: true,
typescript: {
ignoreBuildErrors: true,
},
webpack5: true
}
const { withExpo } = require('@expo/next-adapter')
const withFonts = require('next-fonts')
const withImages = require('next-images')
const withPlugins = require('next-compose-plugins')
const withTM = require('next-transpile-modules')([
'app',
'solito',
'dripsy',
'@dripsy/core',
'nativewind',
'zeego',
])
module.exports = withPlugins(
[withTM, withFonts, withImages, [withExpo, { projectRoot: __dirname }]],
nextConfig
) InfoThey both doing the same thing but;
|
Beta Was this translation helpful? Give feedback.
-
How do I use solito to change routes with i18n. I'm using next-i18next |
Beta Was this translation helpful? Give feedback.
-
Has anybody integrated any i18n library with solito?
I'm trying to make it work with https://github.com/i18next/i18next but there are many issues on both Next and Expo sides.
I think maybe https://github.com/i18next/next-i18next must be used for the Next part but I'm not sure how to make it work for Expo as well.
Beta Was this translation helpful? Give feedback.
All reactions