Custom locale for localization

mrizoiwe98 66 Reputation points

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?

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

1 answer

Sort by: Most helpful
  1. JarvanZhang 23,936 Reputation points

    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 ...   
           <Label Text="{x:Static resources:AppResources.NotesLabel}" />  
           <Entry Placeholder="{x:Static resources:AppResources.NotesPlaceholder}" />  
           <Button Text="{x:Static resources:AppResources.AddButton}" />  
       <ContentPage ...   
           <Label Text="{x:Static resources:AppResources.vague_NotesLabel}" />  
           <Entry Placeholder="{x:Static resources:AppResources.vague_NotesPlaceholder}" />  
           <Button Text="{x:Static resources:AppResources.vague_AddButton}" />  

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

       App.Current.MainPage = new VagueMainPage();  

    ControlTemplate part:

           <ControlTemplate x:Key="normal_template">  
               <Label Text="{x:Static resources:AppResources.NotesLabel}" />  
           <ControlTemplate x:Key="vague_template">  
               <Label Text="{x:Static resources:AppResources.vague_NotesLabel}" />  
           <!--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}">  

    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.