In this article we are going to see how to Localize an application bar while developing Windows Phone application. In our previous article we have seen how to localize the application and also to Globalize the application while designing the application for multiple markets and language specific application. To know about Application bar and its usage please follow the articles (Article1. Article2, Article3) which explains the application bar usages and the different approaches to use the application bar effectively in your application. Let us see how we can localize the application bar programmatically to change based on the resource that is loaded. [more]
Let us see the steps on how to achieve this task in our Windows Phone application development. Open Visual Studio 2012 IDE and create a new Windows Phone project with a valid project name as shown in the screen below.
Clicking on OK will create the project and the solution with the list of default files and folders that are required to run the application. It will take some time to create these files based on your system configuration, so once everything is ready we can see the Visual Studio IDE with the project as shown in the screen below.
Now we have the project ready to see how we are going to Localize the application bar, in the xaml code we have some code base commented which has some basic notes on how to Localize which we have discussed the same in our earlier article. Now go to the code behind and we can see a list of commented section which is some default code that is used to Localize the application bar as shown in the screen below.
Uncomment the method BuildLocalizedApplicationBar and we can see an instance of the application bar is created and some base code which gets the necessary files that are required to build the application bar. To get the localized strings we need to add the strings in the Resource file which is available in the resource folder. In the code we can see the syntax AppResources.AppBarMenuItemText which has the exact localized value in the resources linked as shown in the screen below.
We can customize the values here and it affects the Application Bar effectively while loading the application in the emulator and the device while deployed. So what languages are to be supported for this application build, there should be option to select that. Yes we can do that as well with the Visual Studio Project settings, just right click on the project and select properties and we see an option called Supported Cultures as shown in the screen below.
We can select the languages that are to be used in the resources from the list of available languages. Based on the selection we can have the list of resource files created as shown in the screen below.
Now build and execute the application and we can see the application uses the base culture, on changing the culture info will load the respective culture values. Don’t forget to check the values in all the cultures to see if the values are correct, we can use some third party tools as well to get the culture resources.