Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add .ts and .js as supported file extensions #1576

Closed
wants to merge 2 commits into from

Conversation

Aareksio
Copy link

@Aareksio Aareksio commented Oct 21, 2022

Reviewing the source code of next branch I found no obstacles that would disallow loading locales from js and ts files. It does not support exporting (async) functions, but should be enough for requested feature of joining localization components:

// en.js

import home from '../components/en/home.json'
import about from '../components/en/about.json'

export default {
  home,
  about,
}

@netlify
Copy link

netlify bot commented Oct 21, 2022

Deploy Preview for nuxt-i18n-v8 ready!

Name Link
🔨 Latest commit bcc64c3
🔍 Latest deploy log https://app.netlify.com/sites/nuxt-i18n-v8/deploys/6353118e3f42ed00081f3bec
😎 Deploy Preview https://deploy-preview-1576--nuxt-i18n-v8.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@rchl
Copy link
Collaborator

rchl commented Oct 22, 2022

Ultimately it's up to @kazupon to decide but based on functionality available in the Nuxt 2 version, I would say that support for async functions is something that many would expect and use. So introducing "half-working" solution is probably not a great idea.

@Aareksio
Copy link
Author

@rchl I disagree with calling it "half working" idea.

This feature is requested by many users:
#1448 (comment)
#1448 (comment)
#1448 (comment)
#1462 (comment)
#1462 (comment)
#1511 (comment)

The PR is intentionally kept very compact, to avoid any changes outside of the scope of allowing using static JS/TS files as translation source. Currently the module is in a state where everyone attempting to use JS/TS translations encounters a silent error.

With this PR:

Usage Before PR After PR
JS/TS object silent fail works
JS/TS function silent fail "Not support executable file (e.g. js, cjs, mjs)"

For me it's a win/win situation, instead of silent failure, users get proper error message.

Consciously limiting scope != half working.

@kazupon kazupon added the v8 label Oct 23, 2022 — with Volta.net
Copy link
Collaborator

kazupon commented Oct 23, 2022

Thank you for your contribution!

There is a reason why we currently limit ourselves to formats such as json, json5, and yml.
In order to fully support i18n resources for executable files like js/ts, @intlify/unplugin-vue-i18n used as a vite plugin must support them.

Currently, vue-i18n v9 used as the core of @nuxtjs/i18n, transpiles locale messages into message functions that can be executed as JS.

Currently supported formats such as json, json5 and, yml also support sourcemap when transpiled. sourcemap must be supported in order to support js/ts as a locale messages resource.
The case of message functions must also be considered.

@Aareksio
Copy link
Author

@kazupon This makes a lot of sense. It was too easy to enable the static file support.

The generator function in bundle-tools seems quite complex for JSON alone, I imagine for JS it's going to be even more extensive as there are more edge cases. Definitely out of realm for a first time contribution.

Is there an approach you would recommend for supporting splitting translation files into components?

|- lang
 |- en/
  |- home.json
  |- profile.json

Since @intlify/unplugin-vue-i18n we could perhaps leverage the generated JS for each component and join them somehow. Is it even worth a try in your opinion?

@irishkooky
Copy link

I would like to use this feature, is this pull request going to be merged?

@Aareksio
Copy link
Author

The approach presented in this PR is lacking. It is unlikely to get merged.
Support must be added first to @intlify/unplugin-vue-i18n.

Copy link

@Aareksio
I see. Thanks!

@pumano
Copy link

pumano commented Feb 27, 2023

any news on this feature? in my case I need to use async function for getting i18n data from server and just need to support functions and js files. That works well in nuxt 2 but not works in nuxt 3. Thanks very frustrating because there no breaking change info about it in documentation when updating.

@kazupon if you can tell more about what to do, I can find time for help with that support. Just need to know what to do for add support. Because that feature need me ASAP :)

@pumano
Copy link

pumano commented Feb 27, 2023

add for linking issue #1829

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants