Skip to content

Commit 2d98918

Browse files
committed
fix: Add locales
1 parent 5bf138d commit 2d98918

File tree

2 files changed

+79
-1
lines changed
  • .github/actions/zip
  • RandomGen/Community.PowerToys.Run.Plugin.RandomGen

2 files changed

+79
-1
lines changed

.github/actions/zip/action.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: 'Zip and Upload Artifact'
2+
description: 'Zips a directory and uploads it as an artifact'
3+
inputs:
4+
source:
5+
description: 'Source directory to zip'
6+
required: true
7+
artifact_name:
8+
description: 'Name of the artifact'
9+
required: true
10+
runs:
11+
using: 'composite'
12+
steps:
13+
- name: Zip directory
14+
run: |
15+
zip -r ${{ inputs.artifact_name }}.zip ${{ inputs.source }}
16+
shell: bash
17+
- name: Upload artifact
18+
uses: actions/upload-artifact@v4
19+
with:
20+
name: ${{ inputs.artifact_name }}
21+
path: ${{ inputs.artifact_name }}.zip

RandomGen/Community.PowerToys.Run.Plugin.RandomGen/Main.cs

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)