This is a migrated thread and some comments may be shown as answers.

Localization files and localize stings?

1 Answer 42 Views
This is a migrated thread and some comments may be shown as answers.
Steven
Top achievements
Rank 1
Steven asked on 16 Sep 2020, 01:56 PM

Hello, 

I am currently in the process of localize a webapp. As I understood we're able to create custom localization files (either as a .js file or a .resx file) and use them to replace different labels from telerik components  (e.g 'Drag a column header and drop it here to group by that column' for grid grouping). The localization also includes the formatting of dates and currencies (basically the '.kendo.culture' -js for dates and formatting and the '.kendo.messages' for labels). 

My first question:

Is there a differene between creating a custom .js localization file or a custom .resx file(best practise, usability etc)? Most demos/example just using .js files for the localization and a few tutorials recommend to modifiy the .resx file, so I'm a bit confused. 

Second question:

Is there any way to use a localization file for 'hard strings' inside a html? Basically my ViewModel includes some properties which are displayed directly in a .cshtml file with a key before the property itself. 

For example :

<div>Firstname: @Model.Firstname</div>

 

My goal is to create multiple localization files that includes the key e.g "Firstname" and display it based on the current culture. 

Something like this

<div> @GetLocalizationStringWithWhatever("firstname") : @Model.Firstname </div>
// Result :
// If culture 'German' = <div>Vorname : Joe </div>
// if culture 'France' = <div>Prénom : Joe </div>
// if culture 'Italien' = <div>Nome di battesimo : joe </div>

 

There are probably multiple ways to achieve my goal (e.g safe the keys in a json and read it based on the current culture etc) but im curious if theres anyway to use the telerik (custom) localization files because I need them anyway and I'll be able to use one way to localize my entire webapp. I've tried to find something like that in demos/examples but it seems like theres no example yet. Is it possible?

 

Third question :

This question is very similar to my second question but basically my ViewModel got a few Date properties which are displayed directly in my .cshtml file. Currently I'm displaying them like this:

@Model.RandomDateVariable.Value.ToString("dd.MM.yyyy HH:mm");

The problem is the Dateformat won't change if the culture changes. The grid for example changes the dateformat if the culture changes and I want to achieve something similar directly inside a cshtml file. Again it seems like theres no demo/example/tutorial on how to achieve something like that. Is it possible?

 

Thanks in advance!

Greetings!

1 Answer, 1 is accepted

Sort by
0
Aleksandar
Telerik team
answered on 21 Sep 2020, 12:45 PM

Hello Steven,

Generally speaking, in the majority of scenarios, you should be able to localize the application using the .js files. If you would like to use a particular culture and language, for which a respective translation is not available in the .rsex file you will need to extend those as well. Note that when updating the .resx files a custom version of Kendo.Mvc.dll must be built, following the guidelines here

Currently, translations are not available for every language and some of the localization files may be incomplete. The full list of currently available translations is available in the Kendo UI Core repository. If a translation for a particular message for the widget you use is missing you can extend the messages.js file for the language and add the translation as demonstrated here

Using the JavaScript files to localize the Kendo UI Widgets will not provide localization for hardcoded strings. For this you may indeed consider creating custom .resx files as demonstrated here:

https://docs.microsoft.com/en-us/aspnet/core/fundamentals/localization?view=aspnetcore-3.1

Converting a DateTime object to string and then trying to apply formatting on the client will not work. For example, if you pass a DateTime object for date values to the Grid, you can apply formatting on the client, which will be affected later when globalization and localization are applied.

I hope this helps.

Regards,
Aleksandar
Progress Telerik

Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive, special prizes, and more, for FREE?! Register now for DevReach 2.0(20).

Asked by
Steven
Top achievements
Rank 1
Answers by
Aleksandar
Telerik team
Share this question
or