Reputation: 776
I have a language api written in .net core. Should I call the data from the api as a variable in the code? How can I manage a localization where the data comes from the database? With the i18n package, you can directly access the language options given in the nextjs project. My data comes through an api. What is the most accurate way to manage localization?
As follow:
Upvotes: 0
Views: 879
Reputation: 2056
What you can do:
You return the translation code to your page. (from your API). Example: {"statusCode": 111}
You fill all translations for all status codes with i18n. Example: {"translationStatusCode_111": "bla bla bla", "translationStatusCode_112": "tra la la"}
In your page, you are showing variable as {t(`translationStatusCode_${returned_status_code}`)}
where returned_status_code
variable is your statusCode
of translation returned from your API.
I wrote this example for you from this library, as you are using nextjs.
Upvotes: 1