Open tomasr78 opened 5 years ago
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
.
Is it possible to do that in-code translation without using HttpRequest object? The LocalizedApplication.Current.TextLocalizerForApp
ask for it.
I don't think it does:
public ITextLocalizer TextLocalizerForApp { get { return RootServices.TextLocalizerForApp; } }
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);`
Sorry, I don't have time at the moment. I suggest you build against the source to see what you can come up with.
Those suggestions above are untested BTW so not saying it should work.
@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.
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.