Thanks for the great videos as always, Mario! BTW if you want, update the video title to have "internationalization" instead. Cheers!!
@MarioCarrion
2 жыл бұрын
Thanks for letting me know, I just updated the title, best.
@dawnrazor
2 жыл бұрын
Sorry to nag, but another question would be this. The information you have presented only performs translation of an app. What about a go library? So do the same principles apply? IE the library would create a bundle itself with the languages it supports, then somehow you need to know which language to use, so you provide an Init function for the client to call to specify the language? I want to create a localisation friendly package, but at the moment its confusing as to how to do this properly.
@MarioCarrion
2 жыл бұрын
Yes, same principles apply, one thing I would add is to use "go:embed" to include the translations in the final binary and you would need to define a type in charge of receiving the user language/locale to return the valid strings; this is better explained as blog post really because the video covers the basics, I'll add that to my to do list. Cheers
@dawnrazor
2 жыл бұрын
@@MarioCarrion thanks Mario, I'll look forward to that blog post. In the mean time I will experiment with your very helpful suggestions. go embed is news to me, so I have more research to do. I appreciate the pointer, cheers
@dawnrazor
2 жыл бұрын
Thanks Mario for this video. If you have multiple packags in a module,can you create the bundle in 1 place and have that apply to all the sub packages in a module (or do you have to keep creating bundles on a per file or per package basis)? Also, that comment //go:generate, do you have to put this into every file that contains translateable text, so that it gets picked up when you run the extract command?
@MarioCarrion
2 жыл бұрын
Hello Paul. Yes you could implement a dedicated package "internal/i18n" (or similar) that contains: * All strings to be used, * A way to initialize the locale, and * A way to pull the translated strings using the IDs That way the same strings can be reused and in this case only one "go:generate" instruction will be added to that package where the translatable strings live.
@c0d368
2 жыл бұрын
Hello guys! I would like to understand what are the pros and cons of setting i18n/i10n client side or server side. I'm looking for an article that mentions this.
@MarioCarrion
2 жыл бұрын
Would you mind elaborating a bit more? Because usually clients indicate the i18n/l10n they want to use and then servers honor that request.
@dawnrazor
2 жыл бұрын
Hi again @Mario Carrion, could you explain how go-i18n selects the end users' language. I have looked at all the documentation and code samples and just can't see how this works. The client creates a bundle specifying a list of supported languages and a Localizer from this bundle. But I can't see how the user's language is detected at runtime and then how this affects message localisation. Asking you this question is a last resort, so I hope you know the answer to this (which is not documented), thanks.
@MarioCarrion
2 жыл бұрын
Hello! If you're asking where to get the user's locale, then that's something that depends on the application itself, for example web apps can use the http header "accept-language"; CLIs may use environment variables or whatever the OS offers. It really depends, in the end for this package "i18n.NewLocalizer(bundle, lang)" will accept that value in "lang" to choose the one that matches it.
@dawnrazor
2 жыл бұрын
@@MarioCarrion Hi, I finally figured out what I was looking for. I really misinterpreted the documentation badly. When you create a bundle, you pass in a language tag which is taken to be the default language. This is what sets the language, simples. I hadnt realised that this language is the one that sets the language, I just thought it was expression of what the default language was if the client requests translation of a message in a language that it doesnt support. I also thought there was an automatic detection of the current language, but it doesnt do that at all. If you want auto detection, you can use jibber-jabber, then pass that language into the bundle. That is the strategy I'm using now.
@MarioCarrion
2 жыл бұрын
I'm glad you figure it out, btw there's another alternative to jibber-jabber called github.com/Xuanwo/go-locale, it seems to still be supported, you may consider that instead. Cheers!
Пікірлер: 20