Comments (7)
Then you need to create your own i18next backend, or use i18next-http-backend with a custom parse function.
Something like:
import i18next from 'i18next';
import HttpApi from 'i18next-http-backend';
i18next.use(HttpApi).init({
backend: {
// loadPath: '/locales/{{lng}}/{{ns}}.json',
loadPath: '/locales.json',
parse: (data, language, namespace) => {
return data.Traducciones[language];
}
},
});
?
from i18next-multiload-backend-adapter.
If you like this module don’t forget to star this repo. Make a tweet, share the word or have a look at our https://locize.com to support the devs of this project.
There are many ways to help this project 🙏
from i18next-multiload-backend-adapter.
Sorry, I don't fully understand what you want to achieve.
Can you please elaborate a bit more?
from i18next-multiload-backend-adapter.
Off course,
Actually I have a React project using i18next to achieve changing languages between english and spanish. Currently my locales are stored in the project, so I just have the next init json
i18n.use(LanguageDetector).init({
resources: {
es: {
translations: esLocale,
},
en: {
translations: enLocale,
},
},
fallbackLng: 'es',
debug: false,
ns: ['translations'],
defaultNS: 'translations',
keySeparator: false,
interpolation: {
escapeValue: false,
formatSeparator: ',',
},
react: {
wait: true,
},
});
Now, the problem is we cannot have those locale files on the code, insted we have to store them in a server because they could change frequently. When I make the request to the backend I have the next response res structure:
res = {
Benefits: { ... }
Categories: { ... }
Traducciones: {
name: "Traducciones"
en: { "benefit.brands": "More than 50 leading brands in the market", "benefit.constantvisits": "Constant and personalized visits to our clients", "benefit.delivertime": "Delivery in 48 hours", … }
es: { "benefit.brands": "Más de 50 marcas líderes en el mercado", "benefit.constantvisits": "Visitas constantes y personalizadas a nuestros clientes", "benefit.delivertime": "Entrega en 48 Horas", … }
}
}
were en and es objects (inside Traducciones) are objects I need to make translations.
My question is, how do I use these objects as resourses to init method? If it still not clear please make me know it.
from i18next-multiload-backend-adapter.
I don't think this is solvable with this multiload adapter...
Can't you just split your language files and load them with i18next-http-backend, like in this example? https://github.com/i18next/react-i18next/tree/master/example/react
from i18next-multiload-backend-adapter.
I don't really have access to the backend
from i18next-multiload-backend-adapter.
Yes! That language param of parse function was what I needed!
Thank you much for your fast response!!
from i18next-multiload-backend-adapter.
Related Issues (3)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from i18next-multiload-backend-adapter.