8000 feat(module): support i18n in components by hywax Β· Pull Request #2553 Β· nuxt/ui Β· GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat(module): support i18n in components #2553

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

8000 Merged
merged 26 commits into from
Nov 8, 2024
Merged

Conversation

hywax
Copy link
Contributor
@hywax hywax commented Nov 7, 2024

πŸ”— Linked issue

Resolves #2512

❓ 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)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

It's easy to use:

<script setup lang="ts">
import { de } from '#ui/locale'
</script>

<template>
  <UApp :locale="de">
    <NuxtPage />
  </UApp>
</template>

πŸ“ Checklist

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

8000
Copy link
pkg-pr-new bot commented Nov 7, 2024
pnpm add https://pkg.pr.new/@nuxt/ui@2553

commit: a6d2f5e

@benjamincanac
Copy link
Member

Thanks for drafting this! Is there a way for the user to override the locales?

How would this pair with Nuxt I18n or Vue I18n?

@hywax
Copy link
Contributor Author
hywax commented Nov 7, 2024

There's a way to override. I'm just now in the process of writing documentation to make it clear how to work with this. It's very simple.

Nuxt I18n or Vue I18n will work in parallel, that's no problem. Using them internally I consider overkill. But if sometime later you want to migrate to these packages, you can do it very quickly

@hywax hywax marked this pull request as ready for review November 7, 2024 11:00
@hywax
Copy link
Contributor Author
hywax commented Nov 7, 2024

Looked @nuxt/i18n there is an option there to quickly integrate into a 3rd party module. I think I will rewrite the code on i18n to make full use of the Nuxt ecosystem

@hywax hywax marked this pull request as draft November 7, 2024 11:11
Copy link
Member
benjamincanac commented Nov 7, 2024

You want to install @nuxtjs/i18n in @nuxt/ui? Not sure it's the best idea because we have to handle it for Vue as well. Making a system that integrates well with both is the way to go I think.

Copy link
Member

While making the Internationalization page on the docs, it could be nice to add a few concepts from https://www.radix-vue.com/guides/i18n.html I think.

@hywax
Copy link
Contributor Author
hywax commented Nov 7, 2024

You want to install @nuxtjs/i18n in @nuxt/ui? Not sure it's the best idea because we have to handle it for Vue as well. Making a system that integrates well with both is the way to go I think.

Then leave the current implementation in place? It is universal and will work as it should

@benjamincanac
Copy link
Member
benjamincanac commented Nov 7, 2024

Could we pass a string to the locale prop of the UApp component instead? This would make it easy to do:

<script setup>
const { locale } = useI18n()
</script>

<template>
  <UApp :locale="locale" />
</template>

And maybe we could use the App Config to change the locales? πŸ€”

@benjamincanac benjamincanac added the v3 #1289 label Nov 7, 2024
@hywax
Copy link
Contributor Author
hywax commented Nov 7, 2024

Could we pass a string to the locale prop of the UApp component instead? This would make it easy to do:

It will increase the build. Not everyone needs a lot of languages, usually 1-2.

And maybe we could use the App Config to change the locales? πŸ€”

I don't think there's much point to it. Again, not to inflate the build.

@hywax
Copy link
Contributor Author
hywax commented Nov 7, 2024

I'll get back to this PR tomorrow, I'll add examples in several languages to the documentation

@hywax hywax marked this pull request as ready for review November 8, 2024 10:05
@hywax
Copy link
Contributor Author
hywax commented Nov 8, 2024

@benjamincanac has split the documentation into Nuxt and Vue. The differences are minimal, but they are there

@benjamincanac
Copy link
Member

@hywax I've pushed 4 commits with updated docs and exposed @nuxt/ui/locale if you want to double check!

@hywax
Copy link
Contributor Author
hywax commented Nov 8, 2024

Already checked it out, everything looks great!

Copy link
Member
@benjamincanac benjamincanac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work! Thanks a lot @hywax 😊

@MuhammadM1998
Copy link
Contributor

Would it be a good idea to expose a UiLocale type that provides the schema of the built-in locales? This would allow users to create a custom locale overrides file for the component with type-safety and then pass it to the UApp.

// uiLocaleOverrides.ts
import type { UILocale} from `@nuxt/ui/locale'`

const myLocaleOverrides: UILocale {
  name: 'custom',
  ui: {
    inputMenu: {
      noMatch: 'My custom message',
    }
  }
}

export default myLocaleOverrides;
<script setup>
import uiLocaleOverrides from './uiLocaleOverrides'
</script>

<template>
  <UApp :locale="uiLocaleOverrides">
    <NuxtPage />
  </UApp>
</template>

@hywax
Copy link
Contributor Author
hywax commented Nov 8, 2024

Good idea! I think it's very easy to do. I'll add it tonight

@benjamincanac
Copy link
Member

Should I wait to merge this?

@hywax
Copy link
Contributor Author
hywax commented Nov 8, 2024

Yes πŸ˜‰

@malik-jouda
Copy link
Contributor

@benjamincanac @hywax
i suggest add file ar

@benjamincanac
Copy link
Member

@malik-jouda Feel free to open a PR that targets this 😊

@hywax
Copy link
Contributor Author
hywax commented Nov 8, 2024

@benjamincanac I added a defineLocale helper to help in creating locales. Can you tell me the best way to export it from the package?

Copy link
Member

You can just put it inside src/runtime/composables 😊

@hywax
Copy link
Contributor Author
hywax commented Nov 8, 2024

Done! All that's left is to write the documentation

@hywax
Copy link
Contributor Author
hywax commented Nov 8, 2024

Let's go to v3 branch πŸš€

@benjamincanac benjamincanac merged commit 2636240 into nuxt:v3 Nov 8, 2024
2 checks passed
@benjamincanac
Copy link
Member

Thanks a lot!! 😊

@benjamincanac
Copy link
Member

@hywax Now that I think of it, is the useLocale composable not supposed to be a singleton? We can achieve this using createSharedComposable: https://github.com/nuxt/ui/blob/v3/src/runtime/composables/useKbd.ts#L70

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

Successfully merging this pull request may close these issues.

4 participants
0