Skip to content

Commit d385d05

Browse files
committed
Improved the localization.
- If the `LANG` variable is set to C, Steppable automatically falls back to en-US. - Fix argParse formatting issue.
1 parent a24e18e commit d385d05

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/argParse.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ namespace steppable::__internals::utils
5858

5959
void ProgramArgs::printUsage(const std::string& reason) const
6060
{
61+
// Usage: <programName> <switches> <keywordArgs>
6162
std::cout << $("argParse", "91408f1e-6627-41e5-9707-d8a660c2b86b") << formats::bold << programName << reset
6263
<< " ";
6364

@@ -66,13 +67,16 @@ namespace steppable::__internals::utils
6667
std::cout << colors::brightGreen << '<' << posArg << '>' << " ";
6768

6869
if (not switchDescriptions.empty())
70+
// Siwtches
6971
std::cout << colors::brightGreen << $("argParse", "38f61169-17f1-4a49-870b-814745cdf4c6") << reset;
7072
if (not keywordArgDescriptions.empty())
73+
// Keyword arguments
7174
std::cout << colors::brightGreen << $("argParse", "4f332974-1fd1-43eb-bbbc-8d32071ed735") << reset;
7275
std::cout << '\n';
7376

7477
if (not posArgDescriptions.empty())
7578
{
79+
// Available positional arguments
7680
std::cout << formats::bold << $("argParse", "5d482eea-c4e4-4c4d-89f0-6b33fcc9618c") << reset << '\n';
7781
for (const auto& [posArgName, posArgDescription] : posArgDescriptions)
7882
{
@@ -87,18 +91,22 @@ namespace steppable::__internals::utils
8791

8892
if (not switchDescriptions.empty())
8993
{
94+
// Available switches
9095
std::cout << formats::bold << $("argParse", "10b1c33b-070f-4dfb-be12-a1a4349e76bc") << reset << '\n';
9196
for (const auto& [switchName, switchDescription] : switchDescriptions)
9297
{
9398
std::cout << colors::brightGreen << formats::bold << '[' << '-' << switchName << "] ";
9499
std::cout << '[' << '+' << switchName << "]" << reset << '\n';
95-
std::cout << $("argParse", "227375c6-6ec8-479e-ad39-59f975272c6b") << switchDescription << '\n';
100+
101+
// Enables/Disables {0}.
102+
std::cout << $("argParse", "227375c6-6ec8-479e-ad39-59f975272c6b", { switchDescription }) << '\n';
96103
}
97104
std::cout << reset << '\n';
98105
}
99106

100107
if (not keywordArgDescriptions.empty())
101108
{
109+
// Available keyword arguments
102110
std::cout << formats::bold << $("argParse", "be2d8c84-0dfc-4f52-b450-e34d1cf20c91") << reset << '\n';
103111
for (const auto& [keywordArgName, keywordArgDescription] : keywordArgDescriptions)
104112
{
@@ -117,27 +125,31 @@ namespace steppable::__internals::utils
117125

118126
// Print the footnote only if there are positional arguments that require a number
119127
if (std::ranges::any_of(posArgIsNumber, [](const bool isNumber) { return isNumber; }))
128+
// Requires number
120129
std::cout << $("argParse", "fd67fddb-ca42-4a79-b852-c0bc71aa9969") << "\n";
121130
programSafeExit(-1);
122131
}
123132

124133
std::string ProgramArgs::getPosArg(const size_t index) const
125134
{
126135
if (posArgs.size() <= index)
136+
// Invalid positional argument
127137
printUsage($("argParse", "b782de55-513d-4eda-b068-98d2d6210603") + std::to_string(index));
128138
return posArgs[index];
129139
}
130140

131141
int ProgramArgs::getKeywordArgument(const std::string& name)
132142
{
133143
if (not keywordArgs.contains(name))
144+
// Invalid keyword argument
134145
printUsage($("argParse", "aa26a7f2-0949-454e-b987-42b40348e104") + name);
135146
return keywordArgs[name];
136147
}
137148

138149
bool ProgramArgs::getSwitch(const std::string& name)
139150
{
140151
if (not switches.contains(name))
152+
// Invalid switch
141153
printUsage($("argParse", "2b854b9f-da27-483e-a016-0eb0d26eb9e9") + name);
142154
return switches[name];
143155
}
@@ -177,6 +189,7 @@ namespace steppable::__internals::utils
177189
{
178190
if (not numUtils::isNumber(_arg) and posArgIsNumber[posArgs.size()])
179191
{
192+
// Positional argument is not a number.
180193
output::error("ProgramArgs::parseArgs"s,
181194
$("argParse", "34782921-b560-4706-a2c9-d5c326af2cff", { _arg }));
182195
programSafeExit(-1);

src/getString.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ namespace steppable::localization
7171
// The languages may be in xx_YY format. We need to convert it to xx-YY format.
7272
std::ranges::replace(lang, '_', '-');
7373
// We cannot find the language, so we return "en-US" as the default language.
74-
if (lang.empty())
74+
if (lang.empty() or lang == "C")
7575
lang = "en-US";
7676
return lang;
7777
}
@@ -114,10 +114,10 @@ namespace steppable::localization
114114
{
115115
// LINE FORMAT
116116
// key >> "string"
117-
if (line.front() == '#')
118-
continue; // Skip comments
119117
if (line.empty())
120118
continue; // Skip empty lines
119+
if (line.front() == '#')
120+
continue; // Skip comments
121121
// Get the key and the string
122122
if (std::regex_match(line, STRING_REGEX))
123123
{

0 commit comments

Comments
 (0)