How to access ui translations?

We’ve created resource files with translations per the instructions at https://docs.litium.com/documentation/previous-versions/litium-6/architecture/back-office/translations but how do we access the translations programmatically? They don’t appear to be available via the system strings or the module strings.

Litium version: 6.2.2

Please inject the IStringLocalizer<ClassName> where ClassName is the name of your class, then use _localizer.GetString(“your.text.key.here”)

Thanks. Right now we get an IStringLocalizer instance but GetAllStrings() returns an empty collection. Would this work in a web forms scenario as well, e.g. when constructor injection is not available should we be able to resolve manually using Litium IoC.Resolve()?
Is there any documentation on this on docs.litium.com?

Yes, using IoC resolve should work

Nope, can’t get this to work. Do you by any chance have a working example?

Sorry, please check Deployment.aspx.cs file in Accelerator 6:

SystemStrings.GetValue(“ExampleProductsHeader”, FoundationContext.LanguageID, true)

Where it uses IResourceService.GetResourceString under the hood.

When creating the resource files it is important the folder they are in. If you wan’t to register the resources as “System strings” you should name the folder as “General”, otherwise the folder name is the same as the module name.

The IStringLocalizer<ClassName> looking for a resouce-file that have the same name as the ClassName and I think that file should be placed in the root for the same project. You can read more about the IStringLocalizer at https://docs.microsoft.com/en-us/aspnet/core/fundamentals/localization?view=aspnetcore-2.1

Sorry, but I can’t get this to work. There are no system strings or module strings created no matter which folder I place resource files in. And about the IStringLocalizer, should it work in a ASP.NET 4.6.1 web application? Any other ideas on what we’re missing?
It would be really helpful with some documentation on this.

1 Like

@hans Can you give us little more info about what you have done with some code snippet where you try to use them and maybe an image over the folder structure and the file names that you using?

Perhaps placeholder-folders would be good here, I am not sure where to place the resx files (is it WebSiteArea? Websites?)

When are the strings loaded?
Are they saved to DB?
Do i need to do anything to re-generate strings from resx?

The strings is readed at runtime and as fast they are changed in the resx-file they are updated. They are not stored in database.

The folder structure that the files are using reflected the “old” modules and we have one file for each module. When we started with the new BO UI we decided to only have one file and that is loaded from Administration folder. Example on folder names for the CMS/ECommerce is for ModuleCMS and ModuleECommerce.

The accelerator templates in Litium 7 have all their strings in the administrations-folder, even that the entity is for different types.

Litium 6
Litium 7

1 Like