Git Product home page Git Product logo

Comments (7)

adrai avatar adrai commented on June 3, 2024 1

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.

adrai avatar adrai commented on June 3, 2024 1

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.

adrai avatar adrai commented on June 3, 2024

Sorry, I don't fully understand what you want to achieve.
Can you please elaborate a bit more?

from i18next-multiload-backend-adapter.

DanielJaramillo94 avatar DanielJaramillo94 commented on June 3, 2024

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.

adrai avatar adrai commented on June 3, 2024

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.

DanielJaramillo94 avatar DanielJaramillo94 commented on June 3, 2024

I don't really have access to the backend

from i18next-multiload-backend-adapter.

DanielJaramillo94 avatar DanielJaramillo94 commented on June 3, 2024

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 photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.