M# Tutorials

Learn to build .NET applications with M#. Our step-by-step tutorials will get you up-to-speed rapidly.
If you already know ASP.NET and C#, you can master M# in a week or two.

UI Guidelines for Language Admin

In the previous tutorial, we learned about setting up multi-lingual support for a web application. In this tutorial, we will glance at language management in admin section. We discussed while setting up globalization, that we must have default phrases and respective translations available in the database, because M# frameworks displays translation for each phrase of the page matched in database. Web applications usually have large number of phrases and handling phrase translation requires administration tasks, which are explained in this tutorial.

Managing Languages

In order to add additional languages, we must create a user interface, where all the languages can be managed. For this purpose, we add further properties in Language entity type to allow the user to submit translations of the phrases we export as phrase dictionary. The screenshot below shows that we have added a new property "PhraseDictionray" to store the phrase dictionary containing translations for the relative language. This is the file we export as a blank dictionary with just two columns. "Phrases" column is populated by system at the time of exporting and "Translations" column is populated by user before adding a language. Another property "Flag" is added to make language selection more interactive.

We can use List Module to display the existing languages with a link to existing phrase dictionary, edit button and add new language option as shown below:

Creating Blank Dictionary

In the previous tutorial we created only one entity PhraseTranslation to manage phrases and translations. We can create another entity "LangaugePhrase" separate from PhraseTranslation. The purpose of having two entities is to manage all the default phrases in one entity type "LangaugePhrase" as a blank dictionary. Another useful purpose of having all phrases in one table "dbo.LangaugePhrases" is to be able to export a blank dictionary of default language phrases (Please read tutorial Generating Excel & CSV for more information on exporting files).

M# raises and event "TranslationRequested" before performing translations. This event can be used to save and manage all the default language phrases by hooking to this event in "Application_Start" event of global.asax file.

The code above calls a custom static method "FindOrAddPhrase" in LanguagePhrase entity, which creates a local cache of all the existing phrases and then on each translation request checks if the phrase already exists otherwise adds it to the language phrase database table and updates the local cache.

Now we have a list of all the default phrases, we can add two more buttons on the language management screen to enable administrator to download a list of blank phrases and to edit the default phrases, as shown below:

Managing Translations

Now we have an entity to keep default phrases, which are added automatically using the global event and a Phrase translation file related to each language. We can populate PhraseTranslation table for each language by reading the uploaded "Phrase Dictionary" file in the "OnSaved" method of Language business logic class (Please read tutorial Reading CSV Data and Database.Save for more details on reading files and saving instances).

The screenshot below displays Language entity "onSaved" method to demonstrate how you can populate PhraseTranslation for each language