Custom locale for localization

mrizoiwe98 66 Reputation points
2021-07-10T02:06:52.873+00:00

Hello , I want to have a "safety mode" switch in my app that when enabled I want to use vague strings instead of explicit ones. Do I need to make a custom locale in localization? How is the best way to do it?

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,363 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. JarvanZhang 23,961 Reputation points
    2021-07-12T02:53:31.537+00:00

    Hello @mrizoiwe98 ,​

    Welcome to our Microsoft Q&A platform!

    I want to have a "safety mode" switch in my app that when enabled I want to use vague strings instead of explicit ones.

    First, please add the vague strings to the Resx files. For the 'safety mode', you could create another application template. Set values for the new application template's pages to display the vague strings. When switching to the 'safety mode', naivgate to the safety mode application template via setting App.Current.MainPage.

    You could also try using ControlTemplate in the pages. Change the control template dynamically when you enable the safe mode.

    For example, create two different templates. Display the vague strings in the 'vague page'.

       <ContentPage ...   
           x:Class="TestApplication_5.Page1"  
           xmlns:resources="clr-namespace:LocalizationDemo.Resx">  
           <Label Text="{x:Static resources:AppResources.NotesLabel}" />  
           <Entry Placeholder="{x:Static resources:AppResources.NotesPlaceholder}" />  
           <Button Text="{x:Static resources:AppResources.AddButton}" />  
       </ContentPage>  
    
    
       <ContentPage ...   
           x:Class="TestApplication_5.vague_Page1"  
           xmlns:resources="clr-namespace:LocalizationDemo.Resx">  
           <Label Text="{x:Static resources:AppResources.vague_NotesLabel}" />  
           <Entry Placeholder="{x:Static resources:AppResources.vague_NotesPlaceholder}" />  
           <Button Text="{x:Static resources:AppResources.vague_AddButton}" />  
       </ContentPage>  
    

    Call App.Current.MainPage command to display the new application when you switch to the safe mode.

       App.Current.MainPage = new VagueMainPage();  
    

    ControlTemplate part:

       <ContentPage.Resources>  
           <ControlTemplate x:Key="normal_template">  
               <Label Text="{x:Static resources:AppResources.NotesLabel}" />  
           </ControlTemplate>  
         
           <ControlTemplate x:Key="vague_template">  
               <Label Text="{x:Static resources:AppResources.vague_NotesLabel}" />  
           </ControlTemplate>  
       </ContentPage.Resources>  
         
       <ContentPage.Content>  
           <!--you could change the contrltemplate via triggers, you may need to create a custom bool property for the page and set binding for it-->  
           <ContentView ControlTemplate="{DynamicResource normal_template}">  
                 
           </ContentView>  
       </ContentPage.Content>  
    

    Best Regards,

    Jarvan Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.