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

How to get all translations for all languages for specific text? #378

Open
tomasr78 opened this issue Oct 16, 2018 · 7 comments
Open

How to get all translations for all languages for specific text? #378

tomasr78 opened this issue Oct 16, 2018 · 7 comments

Comments

@tomasr78
Copy link

I have several translations of the text, let's say [[[Sign-In]]]. I would like to iterate all translations and translate that text to MVC Route Table. Two problems here, I only find HttpContext.GetText method for in-code translation which requires HttpContext object which is not available in Routes method yet.
Anyway I think I would have possibility to access Routes later in Controller context.

The main problem how to use HttpContext.GetText("[[[Sign-In]]]") and iterate all languages and get all translation available.

@turquoiseowl
Copy link
Owner

turquoiseowl commented Oct 16, 2018

Off the top of my head you can use i18n.LanguageHelpers.GetAppLanguages() to reference collection of all languages then for each call i18n.Helpers.TextLocalizerExtensions.GetText. First argument would be LocalizedApplication.Current.TextLocalizerForApp.

@tomasr78
Copy link
Author

tomasr78 commented Oct 16, 2018

Is it possible to do that in-code translation without using HttpRequest object? The LocalizedApplication.Current.TextLocalizerForApp ask for it.

@turquoiseowl
Copy link
Owner

I don't think it does:

public ITextLocalizer TextLocalizerForApp { get { return RootServices.TextLocalizerForApp; } }

@tomasr78
Copy link
Author

tomasr78 commented Oct 16, 2018

The code below thrown exception "Request is not available in this context"}: System.Web.HttpException. Could you show how to use it properly in non HttpContext?

    public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
`LocalizedApplication.Current.TextLocalizerForApp.GetText("[[[Sign-In]]]", null, new[] { new LanguageItem(), }, out var langtag);`

@turquoiseowl
Copy link
Owner

Sorry, I don't have time at the moment. I suggest you build against the source to see what you can come up with.

@turquoiseowl
Copy link
Owner

Those suggestions above are untested BTW so not saying it should work.

@MilanDanilovic
Copy link

MilanDanilovic commented Aug 29, 2022

@tomasr78
It is possible. Vaadin framework example:
import com.vaadin.flow.i18n.I18NProvider;

for(Locale locale : i18NProvider.getProvidedLocales()){
      String car = i18NProvider.getTranslation("vehicle.type.car",locale);
 }

Code above will take all available languages to get translation for passed value defined in its properties.

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

No branches or pull requests

3 participants