Skip to content

Commit

Permalink
VPN-5138: Fix pascal case (#9949)
Browse files Browse the repository at this point in the history
* vpn-5138 fix pascal case

* temporary

* preserve behavior for languages

* more temp debug for windows

* windows test

* add comments
  • Loading branch information
mcleinman authored Oct 11, 2024
1 parent ff15a38 commit 3b7b096
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/localizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,33 @@ QString toUpper(const QLocale& locale, QString input) {
return input.replace(0, 1, locale.toUpper(QString(input[0])));
}

QString toPascalCase(const QString& s) {
QString changeCasing(const QString& s, bool shouldLowerCase) {
QStringList words = s.split("_");

for (int i = 0; i < words.size(); i++) {
QString word = words.at(i);
if (!word.isEmpty()) {
words[i] = word.at(0).toUpper() + word.mid(1);
if (shouldLowerCase) {
words[i] = word.at(0).toUpper() + word.mid(1).toLower();
} else {
words[i] = word.at(0).toUpper() + word.mid(1);
}
}
}

return words.join("");
}

// toPascalCase will capitalize the first letter of a word, and make
// all other letters in the word lowercase.
// Examples: McAllen -> Mcallen, en_FS -> EnFs, sample_thing -> SampleThing
QString toPascalCase(const QString& s) { return changeCasing(s, true); }

// toLanguageId will capitalize the first letter of a word, and keep
// all other letters in the word the same case as the input.
// Examples: McAllen -> McAllen, en_FS -> EnFS, sample_thing -> SampleThing
QString toLanguageId(const QString& s) { return changeCasing(s, false); }

} // namespace

// static
Expand Down Expand Up @@ -490,7 +504,7 @@ int Localizer::rowCount(const QModelIndex&) const {
}

QString Localizer::localizedLanguageName(const QString& languageCode) const {
QString i18nLangId = QString("Languages%1").arg(toPascalCase(languageCode));
QString i18nLangId = QString("Languages%1").arg(toLanguageId(languageCode));
QString value = getCapitalizedStringFromI18n(i18nLangId);

// Value should never be empty, because the ultimate fallback locale is "en"
Expand Down Expand Up @@ -634,11 +648,12 @@ QString Localizer::getTranslatedCityName(const QString& cityName) const {
// Malmö -> ServersMalm, São Paulo, SP -> ServersSoPaulo, Berlin, BE ->
// ServersBerlin

QRegularExpression acceptedChars("[^a-zA-Z]");
QRegularExpression acceptedChars("[^a-zA-Z ]");
QString parsedCityName =
cityName.split(u',')[0]
.replace(" ", "") // Remove state suffix
.replace(acceptedChars, ""); // Remove special characters
cityName
.split(u',')[0] // Remove state suffix
.replace(acceptedChars, "") // Remove special characters
.replace(" ", "_"); // Prepare for toPascalCase

QString i18nCityId = QString("Servers%1").arg(toPascalCase(parsedCityName));

Expand Down

0 comments on commit 3b7b096

Please sign in to comment.