Next-translate: Allow using .js files in translations instead of .json

Created on 10 Nov 2020  路  5Comments  路  Source: vinissimus/next-translate

Hi, I'd like to use .js files as locale translations, eg. "en -> common.js" where I could import some constants and use them as keys instead of manually writing key names, etc. Is this possible? Thanks
image

So I don't get an error like this
image

Most helpful comment

@alexnm2566 nice, I just did the 0.19.5 release 馃槣 thank you very much for reporting it, if you find how to improve the library further do not hesitate to report it!

All 5 comments

@alexnm2566 We can remove the .json from the import to allow other formats like .js, however it will only work if in the .js file you are exporting a json with the translations in the same way than .json. Will this work for you? If so, we can make this fix for the next release, it's easy to do.

if this doesn't work for you, we are developing the version 1.0 of this library, and this changes a little bit, allowing to download the namespaces from whereever. You can experiment with 1.0.0-experimental.3 (It's quite experimental yet).

Instead of:

{
  localesPath: 'locales'
}

you will be able to do this:

{
  loadLocaleFrom: (locale, namespace) => import(`./locales/${locale}/${namespace}.js`).then((m) => m.default)
}

Furthermore, that there is no longer any need to "build step" in 1.0 and more advantages. It's probable that there are broken things, but well, if you try it and things fail, let me know and we'll fix it! Thank you!

@aralroca Yes, thank you! Both the methods will work perfectly for me

@alexnm2566 Then, in the next release 0.19.5 you will be able to use it! I made a 0.19.5-canary.2 pre-release if you want to try it out and confirm that it works, let me know! Thank you!

@aralroca Wow thank you very much! This is great! :) 0.19.5-canary.2 worked perfectly for me, thanks!

@alexnm2566 nice, I just did the 0.19.5 release 馃槣 thank you very much for reporting it, if you find how to improve the library further do not hesitate to report it!

Was this page helpful?
0 / 5 - 0 ratings