![ilocalize iphone ilocalize iphone](https://www.idevice.ro/wp-content/plugins/AppStoreZaone/images/mzl.ltbgxjng.800x500-75.jpg)
Once you have this extension you could start to use it in your xaml code.
#Ilocalize iphone code
Here is the code for the markup extension: In this method, we will call an instance of the resource manager and try to get the value for the key and culture we’ve provided.
![ilocalize iphone ilocalize iphone](https://www.idevice.ro/wp-content/plugins/AppStoreZaone/images/mza_2616162424882700498.800x500-75.jpg)
To get the value for a specific key we have to implement the ProvideValue method. Inside the markup extension, we only check on which platform (iOS, Android) the code is currently running on and call the corresponding dependency service to get the preferred language. To be able to do this we need to write a small xaml markup extension that will load the value string for a provided key.Ĭreating a new custom markup extension is super easy ? Just create a new file called “TranslateExtension.cs” and inherit from IMarkupExtension. When we’ve entered all the strings we want to use in our UI we’ve prepared everything we needed for our app to be able to work with multiple languages! The last missing thing we need to do is to tell our xaml code to load the strings from the resource files. I have to say that I’ve not tried this but it seems like a reasonable workaround. If you don’t want to edit xml code there is a way to convert the resource file and edit it with an external program. If you’ve had a lot of strings in your resource file this could be a bit of a mess to overview.
#Ilocalize iphone for mac
Visual Studio for Mac and Resource filesĭue to the missing resource editor in visual studio for Mac, you need to edit the file as XML based file.
![ilocalize iphone ilocalize iphone](http://beta.tig7.de/tig7_mitglieder/30.jpg)
Now that we’ve created the file we can add the strings we need in the UI’s. To create this file go ahead and create a new folder in your shared project called “Languages”.Ĭreate a new resource file called “AppResource.resx” into the folder you’ve just created. When you’ve created the dependency service to get the preferred device language we can continue to create the resource file which contains the texts we are going to use. If we couldn’t load any language we will use English as the default language. We load the language from the device and set the culture of the current thread and UI thread to the language we’ve loaded.
#Ilocalize iphone android
The implementation in android is pretty much the same as in iOS. With the SetLanguage() method we will set the culture of the current thread and UI thread to the preferred language we’ve just loaded from the device. In the iOS implementation, the GetPreferredLanguage() method gets, as the name suggested, the preferred language of the current iOS device.
![ilocalize iphone ilocalize iphone](https://www.idevice.ro/wp-content/plugins/AppStoreZaone/images/mzl.qfbtwrqr.800x500-75.jpg)
If you’ve created the interface head over to the Android and iOS project to implement the logic for each platform. The first thing we need to do is to create an interface for our dependency service. If you do not know what a dependency service is or how they work check out this post where I explain dependency services in Xamarin. To do so we can create a so-called dependency service to get the preferred language for each platform (iOS, Android) in the shared code. It’s not that bad if you have already started without, but it could be some extra work for you to change the hardcoded strings… Add multi-language supportīefore we gonna start with adding resource files for our texts, we need to find out which language the user prefers. To do so it’s the easiest way to add multi-language support before you gonna design your pages and hardcode every single string inside the controls or the view models. But to reach more people especially in different countries it’s important that our apps will support multiple languages! We’re always trying to reach more people with the apps we create.