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

feat: support js and ts extension resource formats #1938

Merged
merged 25 commits into from
Mar 23, 2023
Merged

Conversation

kazupon
Copy link
Collaborator

@kazupon kazupon commented Mar 15, 2023

πŸ”— Linked issue

close #1576
close #1448

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@pumano
Copy link

pumano commented Mar 17, 2023

@kazupon would love if it will be merged soon and released! Thank you for that feature!

@ineshbose
Copy link
Collaborator

Good things come to those who wait πŸ˜‰

@kazupon kazupon marked this pull request as ready for review March 18, 2023 19:17
src/module.ts Outdated Show resolved Hide resolved
@ineshbose
Copy link
Collaborator

How about a composable to help locale functions be typed?

Something like:

type LocaleFunction = (context: NuxtApp, locale: Locale) => MaybePromise<Record<string, any> | any>
export const defineI18nLocale = (p: LocaleFunction) => p

Also, maybe context: NuxtApp as a parameter could move to the last and be defaulted as context = useNuxt() (from @nuxt/kit, but depends on the context of the function)?

@kazupon
Copy link
Collaborator Author

kazupon commented Mar 20, 2023

Thank you for your review!!

How about a composable to help locale functions be typed?

Sorry, What do that compostables mean?
I could not understand that use case πŸ˜…

The functionality we will support is defined in the langDir module option, and the context and locale passed in that function are passed in the nuxt i18n module. I didn't understand the benefit of making it composable.

@ineshbose
Copy link
Collaborator

I may not be using the term appropriately, but just a helper/wrapper function used in JavaScript files in langDir to help ensure that the function is typed and valid. Similar to how defineNuxtConfig allowing Nuxt configurations to be typed according to NuxtSchema otherwise nuxt.config.ts could also look like:

export default {
  modules: ['@nuxtjs/i18n'],
  i18n: {}
}

But this wouldn't be an easily typed config (also without JSDoc). So with the composable, this is what I mean:

export default defineI18nLocale((context, locale) => {
  return {}
})

compared to

export default function (context, locale) => {
  // what types are context and locale??
}

Because defineI18nLocale is just a small wrapper/helper function (with no logic other than just returning the function inside - also very similar to defineNuxtPlugin) - it would at least ensure that context and locale and also the return type are valid without having to mention NuxtApp or Locale that also won't be able to used in non-typescript files.

If this is still confusing, that's fine - I can still make a separate PR for it myself immediately after this has been merged.

@pumano
Copy link

pumano commented Mar 22, 2023

@ineshbose could you please review? I'm counting days and hours when it will be released πŸ˜…

@ineshbose
Copy link
Collaborator

@pumano I'm reviewing the changes continuously - but it'll be kazupon himself to decide when it's ready πŸ™‚

@kazupon kazupon merged commit c0b701c into next Mar 23, 2023
@kazupon kazupon deleted the feat/ts-js-resources branch March 23, 2023 05:44
@pumano
Copy link

pumano commented Mar 23, 2023

@kazupon could you please release new version? I'm really need this feature.

@ineshbose
Copy link
Collaborator

ineshbose commented Mar 23, 2023

It should be released on edge (just checked, doesn't seem to be there πŸ€”), but a tagged release may take a while.

@steel97
Copy link

steel97 commented Mar 23, 2023

@ineshbose it looks like release edge step was skipped
ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅

@kazupon
Copy link
Collaborator Author

kazupon commented Mar 23, 2023

I've just tried to release with github action
https://github.com/nuxt-modules/i18n/actions/runs/4502384367/jobs/7924323710

@tushar-compro
Copy link

Hi @kazupon ,

Is there any timeline when js/ts will be available for localization files? Or is it already there and I'm missing something? because I'm still not able to use files like en.js, es.js etc although en.json is working fine.

Regards

Copy link
Collaborator Author

kazupon commented Aug 24, 2023

You can conigure experimental.jsTsFormatResource: true.
docs is saying:
https://v8.i18n.nuxtjs.org/guide/lazy-load-translations

nuxt i18n is currently v8 RC, so it will be made available by default if no critical issues are reported.

DarthGigi pushed a commit to DarthGigi/i18n that referenced this pull request Apr 16, 2024
* docs: typos

* feat: support js and ts extension resource formats

* add server handler skelton

* feat: support js and ts extension resource formats

* add server handler skelton

* basic implementation

* refactor

* support ssg

* update snapshot

* bump

* fix: change to $config using

* fix: strip type annotation on typescript codes

* refactoring

* docs: updates

* fix: updates

* fix: more updates

* add defineI18nLocale

* remove unnecesary deps

* add `precompile` options

* fix: update snapshots

* chore: bump deps

* docs: updates

* refactor: remove codes

---------

Co-authored-by: pierresaid <said.pierre.emler@gmail.com>
Co-authored-by: Inesh Bose <56732164+ineshbose@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[next] is it possible to use js/ts files for localization?
6 participants