@@ -62,10 +62,29 @@ public class Main : IPlugin, IContextMenu, IDisposable
6262 private bool Disposed { get ; set ; }
6363
6464 private Faker _faker ;
65+ private string _locale = "en" ;
66+
67+ private static readonly HashSet < string > SupportedLocales = new (
68+ new [ ] {
69+ "af_ZA" , "ar" , "az" , "cz" , "de" , "de_AT" , "de_CH" , "el" , "en" , "en_AU" , "en_AU_ocker" ,
70+ "en_BORK" , "en_CA" , "en_GB" , "en_IE" , "en_IND" , "en_NG" , "en_US" , "en_ZA" , "es" ,
71+ "es_MX" , "fa" , "fi" , "fr" , "fr_CA" , "fr_CH" , "ge" , "hr" , "id_ID" , "it" , "ja" , "ko" , "lv" ,
72+ "nb_NO" , "ne" , "nl" , "nl_BE" , "pl" , "pt_BR" , "pt_PT" , "ro" , "ru" , "sk" , "sv" , "tr" , "uk" , "vi" ,
73+ "zh_CN" , "zh_TW" , "zu_ZA"
74+ } ) ;
6575
6676 private Faker GetFaker ( )
6777 {
68- return _faker ??= new Faker ( ) ;
78+ return _faker ??= new Faker ( _locale ) ;
79+ }
80+
81+ private void SetLocale ( string locale )
82+ {
83+ if ( SupportedLocales . Contains ( locale ) )
84+ {
85+ _locale = locale ;
86+ _faker = new Faker ( _locale ) ;
87+ }
6988 }
7089
7190 // Method to clean up duplicate action keyword prefixes
@@ -129,6 +148,7 @@ public List<Result> Query(Query query)
129148 "color" => [ GenerateColor ( ) ] ,
130149 "url" => [ GenerateUrl ( ) ] ,
131150 "credit" or "creditcard" => [ GenerateCreditCard ( ) ] ,
151+ "locale" => [ ChangeLocale ( parameters ) ] ,
132152 _ => GetFilteredSuggestions ( command )
133153 } ;
134154 }
@@ -519,6 +539,41 @@ private List<Result> GetHelpResults()
519539 return
520540 [
521541 CreateHelpResult ( "password [length] [options]" , "Generate random password (default: 12 chars)" , "password 16 -special" ) ,
542+ private Result ChangeLocale( string parameter )
543+ {
544+ if ( string . IsNullOrWhiteSpace ( parameter ) )
545+ {
546+ return new Result
547+ {
548+ QueryTextDisplay = "locale" ,
549+ IcoPath = IconPath ,
550+ Title = $ "Current locale: { _locale } ",
551+ SubTitle = "Specify a locale code to change" ,
552+ } ;
553+ }
554+
555+ var code = parameter . Trim ( ) ;
556+ if ( ! SupportedLocales . Contains ( code ) )
557+ {
558+ return new Result
559+ {
560+ QueryTextDisplay = $ "locale { code } ",
561+ IcoPath = IconPath ,
562+ Title = "Invalid locale" ,
563+ SubTitle = $ "Supported: { string . Join ( "," , SupportedLocales ) } ",
564+ } ;
565+ }
566+
567+ SetLocale ( code ) ;
568+ return new Result
569+ {
570+ QueryTextDisplay = $ "locale { code } ",
571+ IcoPath = IconPath ,
572+ Title = $ "Locale set to { code } ",
573+ SubTitle = "Locale changed for future results" ,
574+ } ;
575+ }
576+
522577 CreateHelpResult ( "pwd [ length ] [ options ] ", "Generate password with options (-lower, -upper, -numeric, -special)" , "pwd 20 -symbols" ) ,
523578 CreateHelpResult ( "email" , "Generate random email address" , "email" ) ,
524579 CreateHelpResult ( "name" , "Generate random full name" , "name" ) ,
@@ -555,6 +610,7 @@ private List<Result> GetFilteredSuggestions(string query)
555610 ( "color" , "Generate random hex color" , "color" ) ,
556611 ( "url" , "Generate random URL" , "url" ) ,
557612 ( "credit" , "Generate random credit card number" , "credit" ) ,
613+ ( "locale" , "Change data generation locale" , "locale fr" ) ,
558614 ( "creditcard" , "Generate random credit card number" , "creditcard" )
559615 } ;
560616
@@ -888,4 +944,5 @@ protected virtual void Dispose(bool disposing)
888944 Disposed = true ;
889945 }
890946 }
947+ }
891948}
0 commit comments