-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
i18n: localized / translated routes #1130
Conversation
@pz-mxu is attempting to deploy a commit to the Svelte Team on Vercel. A member of the Team first needs to authorize it. |
Answering here to some comments in #1037 @pz-mxu
Maybe you're importing the runtime library instead of the built time plugin? Check this: https://github.com/cibernox/sveltekit-bug-with-plugin/blob/main/svelte.config.cjs
I'm not so sure about that because it's very common for translations to have dashes for word separations (e.g. On that, since this library is the new kid in the block I wanted to make as easy as possible for people to give it a go. Svelte-i18n is by a fair margin the most popular library (and IMO the best too), so I chose to copy (sometimes literally copying chunks of code) from that one. I'm hesitant to come up with a new API when this one is so battle tested already.
It's curious, my experience is exactly the opposite. Certainly in web the ICU message format is the most popular on the web (I am yet to see a web app using gettext), but even on android and iphone apps I never saw gettext used. I think I remember seeing it in a java project, but even on java the ICU message format is what I saw the most. On those projects I worked with translation agencias and they seemed to have al the tooling they needed. Regardless, the approach of my library is to compile translations into javascript functions ad build time, I think it would be amicable to supporting more than one i18n syntax like gettext or projectfluent, we'd just have to build a different plugin that can compile gettext |
@cibernox |
@floratmin I'm using messageformat already, but I'm using only the parser. But it's great to know that |
I didn't mean the import for Vite plugin. When I want to translate route segments with a function that is invoked during manifest creation, I need access to the compiled translations at this point. |
I may have to give it a go, I didn't consider importing translations from anywhere but application code. If you need to import it at build time for creating a manifest I need to check. If you can create a brach and link me to it I'll check it tonight. |
8a5bef0
to
d2ba69a
Compare
I'm really excited to see this work. This is exactly the kind of thing I need to get an i18n app working smoothly. I know this is probably still a work in progress, but I wanted to provide some feedback after playing around with this. Allow
|
const params = parent_params.slice(); | |
params.push(...item.parts.filter((p) => p.dynamic).map((p) => p.content)); |
it would be nice to have the option to add a dynamic segment like locale
as a path parameter by doing something like:
alternateRoutes: (segments) => {
return [
segments,
// Ex. /{locale}/rest/of/path
[
[{ content: "locale", dynamic: true, spread: false }],
...segments
]
];
}
Ease of Use
I honestly am not 100% sure about this idea but I think we need a more intuitive way to work with configuring alternateRoutes
. What if instead of using segments
, alternateRoutes
could be configured like this:
alternateRoutes: (path) => {
return [
path,
`/{locale}${path}`
];
}
I think this would align more with how a svelte-kit user thinks about routing. But I can see how using segments
might be easier to manipulate?
Let me know what you think and if there is anything you would like me to help with, I'd love to contribute.
Thanks
Allowing it for endpoints is an option, but if we do that, the alternativeRoutes() function should also get the route's type. Some people might not want to localize endpoints.
Interesting idea, I haven't thought about that yet. Will try to add the possibility and we can play around with it.
I thought about that, too. But using the internal structure makes it easier to work with. Of course this way it's dependent on the internal structure of segments, that could maybe change some time. But I thought that the alternateRoutes() functions will probably be implemented by i18n-libraries, not directly by the user of svelte kit, although possible. |
Just added another code change proposal: pzerelles#2 (comment) |
packages/create-svelte/templates/default/src/routes/index.svelte
Outdated
Show resolved
Hide resolved
5214872
to
15851cd
Compare
I cleaned up the branch and rebased on the latest master. |
15851cd
to
f62c81c
Compare
141ca6f
to
b6e910f
Compare
ebd1893
to
328e145
Compare
What's the status on this branch? I'm interested by i18n routes |
328e145
to
f2a3244
Compare
|
f2a3244
to
6ab0029
Compare
729357c
to
3545d69
Compare
✔️ Deploy Preview for kit-demo canceled. 🔨 Explore the source changes: dd52462 🔍 Inspect the deploy log: https://app.netlify.com/sites/kit-demo/deploys/61f80cb475268200085e3223 |
3545d69
to
e8e0208
Compare
e8e0208
to
86384be
Compare
86384be
to
d28d4b9
Compare
d28d4b9
to
df3d430
Compare
df3d430
to
58a3d0a
Compare
58a3d0a
to
dd52462
Compare
Yes please 😍 any news on this PR? seems a little abandoned? |
@@ -1,6 +1,6 @@ | |||
{ | |||
"name": "@sveltejs/kit", | |||
"version": "1.0.0-next.251", | |||
"version": "1.0.0-next.252", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this does not belong in a feature PR
@@ -1,5 +1,11 @@ | |||
# @sveltejs/kit | |||
|
|||
## 1.0.0-next.252 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
feature PRs must not modify the changelog
Given that this has been sitting around for ~3 years and the ecosystem has come a long way, I'm going to go ahead and close this. |
This is now just a part of what #1037 implemented and also in a different way. The goal was to make alternate routes for the same page configurable.
There is a new configuration property "alternateRoutes" in the "kit" section of svelte.config.cjs. It optionally takes a function that receives a page's Part[][] and returns Part[][][], so the routes can be multiplied and the segments in Part[][] changed. This can be used e.g. to translate the routes or add a locale prefix.
Since the router has all the routes on the client, there is an alternates() function in "$app/navigation" that will return all alternate paths of a path. This is useful for language choosers for example.
I also added a usage example to "examples/svelte-kit-demo". Currently no translation is happening. This can be dealt with using translation libraries like svelte-i18n or svelte-intl-precompile.