Atlantis
Atlantis

Reputation: 775

Xamarin Forms localization and mvvm

I'm receiving data from the server and I should localize it and put it in ViewModel.

I serialize data from responce in json format to .NET object.

For example, I need to localize boolean variable "True" or "False" to English or different UI language to "Free" or "Busy".

I use resources files (*.resx) for localization.

Suggest me the best way to do it in Xamarin.Forms app with classic MVVM.

Upvotes: 0

Views: 889

Answers (1)

Ahmad ElMadi
Ahmad ElMadi

Reputation: 2617

Here is a very detailed documentation of how would add localization to your project using resx.

In your case when you get the True then I request the localized key for "Free" .

For example if you have a property called Status you do localize it this way

 public string Status
        {
            get
            {
                if (_isBusy)
                {
                    return AppResources.Status_Busy;
                }
                else
                {
                    return AppResources.Status_Free;
                }
            }
            set
            {
                _status = value;
                OnPropertyChanged(); 
            }
        }

Upvotes: 1

Related Questions