Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VPN-5138: Fix pascal case #9949

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions src/localizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,27 @@ 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("");
}

QString toPascalCase(const QString& s) { return changeCasing(s, true); }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be helpful to add a comment for our future selves and any poor souls who come after us about when we expect to use toPascalCase vs toLanguageId.


QString toLanguageId(const QString& s) { return changeCasing(s, false); }

} // namespace

// static
Expand Down Expand Up @@ -490,7 +498,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 +642,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
Loading