nuxt-modules / i18n

I18n module for Nuxt
https://i18n.nuxtjs.org
MIT License
1.75k stars 483 forks source link

feat: experimental auto import translation functions #2847

Closed BobbieGoede closed 8 months ago

BobbieGoede commented 8 months ago

๐Ÿ”— Linked issue

โ“ Type of change

๐Ÿ“š Description

Resolves #1644

Adds experimental.autoImportTranslationFunctions, which when enabled adds $t, $d and $n to globalThis.

I did add the option to the docs but it's the bare minimum, not sure where and how to describe it in a clearer way ๐Ÿค”, I suppose it's not that big of a deal while it's an experimental feature?

๐Ÿ“ Checklist

nuxt-studio[bot] commented 8 months ago

Live Preview ready!

Name Edit Preview Latest Commit
i18n Edit on Studio โ†—๏ธŽ View Live Preview 05c513f24f432833e5f058f53bc45ed3819f23d4
kazupon commented 8 months ago

Great work! I am glad you have improved nuxt i18n dx!

Another implementation way for auto impot is to use AST in the bundler transform, which implements nuxt auto-import, or macros such as unplugin-auto-import, or like Vue 3 defineProps macro way, so we can generate useI18n executable code.

This method is advanced and difficult to implement, but by injecting the transformed code into the script setup, we don't have worry about releases.

BobbieGoede commented 8 months ago

Another implementation way for auto impot is to use AST in the bundler transform, which implements nuxt auto-import, or macros such as unplugin-auto-import, or like Vue 3 defineProps macro way, so we can generate useI18n executable code.

This method is advanced and difficult to implement, but by injecting the transformed code into the script setup, we don't have worry about releases.

Ah yes! I never considered this approach, I'll close this PR for now and see if I can work out a solution using this method. This will give us more control where this functionality is injected, and I'm interested in learning more about this anyway ๐Ÿ˜„.