-
Notifications
You must be signed in to change notification settings - Fork 81
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
Prepare supporting additional languages #1397
Merged
+360
−206
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
4ffea12
Add unit tests for plLocalization::LocalToString/StringToLocal
dgelessus 9b8e41d
Refactor plLocalization::StringToLocal a bit
dgelessus c98e8e9
Refactor iterating over all defined languages
dgelessus b521789
Add simpler method for getting all language names
dgelessus 5de8a00
Make plLocalization::LocalToString skip languages with empty values
dgelessus 631cadb
Show missing translation warnings only for usable languages
dgelessus 697f6e2
Allow choosing unsupported languages with an internal client
dgelessus cb59fd9
Remove placeholder Japanese loading text translation
dgelessus 944b31d
Don't hardcode language list in App.SetLanguage implementation
dgelessus 2dee860
Define new languages Dutch, Russian, Polish, Czech
dgelessus 87772b5
Replace another language number with a symbolic constant
dgelessus 5a7b9af
Apply suggestions from code review
dgelessus 083d3d0
Fix OOB vector accesses when rendering unsupported characters
dgelessus 3485e4d
Declare Russian as a usable language
dgelessus bb66f12
Convert hardcoded translated strings to UTF-8
dgelessus 3b29f8a
Add Russian translations of hardcoded strings
dgelessus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,6 +126,7 @@ You can contact Cyan Worlds, Inc. by email [email protected] | |
#include "pfCamera/plVirtualCamNeu.h" | ||
|
||
#include <algorithm> | ||
#include <string_theory/string> | ||
|
||
//#define MF_TOSSER | ||
|
||
|
@@ -1849,17 +1850,36 @@ void plDXPipeline::ICreateDynamicBuffers() | |
|
||
void plDXPipeline::IPrintDeviceInitError() | ||
{ | ||
char str[256]; | ||
char err[16]; | ||
ST::string caption; | ||
ST::string message; | ||
switch(plLocalization::GetLanguage()) | ||
{ | ||
case plLocalization::kFrench: strcpy(err, "Erreur"); strcpy(str, "Erreur d'initialisation de votre carte graphique. Les valeurs par d�faut de ses param�tres ont �t� r�tablis. "); break; | ||
case plLocalization::kGerman: strcpy(err, "Fehler"); strcpy(str, "Bei der Initialisierung Ihrer Grafikkarte ist ein Fehler aufgetreten. Standardeinstellungen werden wiederhergestellt."); break; | ||
case plLocalization::kSpanish: strcpy(err, "Error"); strcpy(str, "Ocurri� un error al inicializar tu tarjeta de v�deo. Hemos restaurado los ajustes por defecto. "); break; | ||
case plLocalization::kItalian: strcpy(err, "Errore"); strcpy(str, "Errore di inizializzazione della scheda video. Sono state ripristinate le impostazioni predefinite."); break; | ||
default: strcpy(err, "Error"); strcpy(str, "There was an error initializing your video card. We have reset it to its Default settings."); break; | ||
case plLocalization::kFrench: | ||
caption = ST_LITERAL("Erreur"); | ||
message = ST_LITERAL("Erreur d'initialisation de votre carte graphique. Les valeurs par défaut de ses paramètres ont été rétablis. "); | ||
break; | ||
case plLocalization::kGerman: | ||
caption = ST_LITERAL("Fehler"); | ||
message = ST_LITERAL("Bei der Initialisierung Ihrer Grafikkarte ist ein Fehler aufgetreten. Standardeinstellungen werden wiederhergestellt."); | ||
break; | ||
case plLocalization::kSpanish: | ||
caption = ST_LITERAL("Error"); | ||
message = ST_LITERAL("Ocurrió un error al inicializar tu tarjeta de vídeo. Hemos restaurado los ajustes por defecto. "); | ||
break; | ||
case plLocalization::kItalian: | ||
caption = ST_LITERAL("Errore"); | ||
message = ST_LITERAL("Errore di inizializzazione della scheda video. Sono state ripristinate le impostazioni predefinite."); | ||
break; | ||
case plLocalization::kRussian: | ||
caption = ST_LITERAL("Ошибка"); | ||
message = ST_LITERAL("Произошла ошибка инициализации вашей видеокарты. Мы сбросили настройки по умолчанию."); | ||
break; | ||
default: | ||
caption = ST_LITERAL("Error"); | ||
message = ST_LITERAL("There was an error initializing your video card. We have reset it to its Default settings."); | ||
break; | ||
} | ||
hsMessageBox(str, err, hsMessageBoxNormal, hsMessageBoxIconError); | ||
hsMessageBox(message.to_wchar().c_str(), caption.to_wchar().c_str(), hsMessageBoxNormal, hsMessageBoxIconError); | ||
} | ||
|
||
// Reset device creation parameters to default and write to ini file | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,9 +58,8 @@ You can contact Cyan Worlds, Inc. by email [email protected] | |
|
||
#include <expat.h> | ||
|
||
#include <algorithm> | ||
#include <stack> | ||
#include <unordered_set> | ||
|
||
|
||
////////////////////////////////////////////////////////////////////// | ||
// | ||
|
@@ -518,15 +517,7 @@ void LocalizationDatabase::IMergeData() | |
|
||
void LocalizationDatabase::IVerifyElement(const ST::string &ageName, const ST::string &setName, LocalizationXMLFile::set::iterator& curElement) | ||
{ | ||
std::unordered_set<ST::string> languageNames; | ||
ST::string defaultLanguage = plLocalization::GetLanguageName((plLocalization::Language)0); | ||
|
||
int numLocales = plLocalization::GetNumLocales(); | ||
for (int curLocale = 0; curLocale <= numLocales; curLocale++) | ||
{ | ||
ST::string name = plLocalization::GetLanguageName((plLocalization::Language)curLocale); | ||
languageNames.emplace(std::move(name)); | ||
} | ||
auto languageNames = plLocalization::GetAllLanguageNames(); | ||
|
||
ST::string elementName = curElement->first; | ||
LocalizationXMLFile::element& theElement = curElement->second; | ||
|
@@ -535,7 +526,7 @@ void LocalizationDatabase::IVerifyElement(const ST::string &ageName, const ST::s | |
while (curTranslation != theElement.end()) | ||
{ | ||
// Make sure this language exists! | ||
auto languageIt = languageNames.find(curTranslation->first); | ||
auto languageIt = std::find(languageNames.begin(), languageNames.end(), curTranslation->first); | ||
|
||
if (languageIt == languageNames.end()) | ||
{ | ||
|
@@ -547,12 +538,11 @@ void LocalizationDatabase::IVerifyElement(const ST::string &ageName, const ST::s | |
curTranslation++; | ||
} | ||
|
||
for (const auto& language : languageNames) | ||
{ | ||
if (theElement.find(language) == theElement.end()) | ||
{ | ||
for (auto lang : plLocalization::GetAllLanguages()) { | ||
ST::string langName = plLocalization::GetLanguageName(lang); | ||
if (plLocalization::IsLanguageUsable(lang) && theElement.find(langName) == theElement.end()) { | ||
pfLocalizationDataMgr::GetLog()->AddLineF("WARNING: Language {} is missing from the translations in element {}.{}.{}. You'll want to get translations for that!", | ||
language, ageName, setName, elementName); | ||
langName, ageName, setName, elementName); | ||
} | ||
} | ||
} | ||
|
@@ -564,7 +554,7 @@ void LocalizationDatabase::IVerifySet(const ST::string &ageName, const ST::strin | |
LocalizationXMLFile::set& theSet = fData[ageName][setName]; | ||
LocalizationXMLFile::set::iterator curElement = theSet.begin(); | ||
|
||
ST::string defaultLanguage = plLocalization::GetLanguageName((plLocalization::Language)0); | ||
ST::string defaultLanguage = plLocalization::GetLanguageName(plLocalization::kEnglish); | ||
|
||
while (curElement != theSet.end()) | ||
{ | ||
|
@@ -817,44 +807,13 @@ pfLocalizationDataMgr::~pfLocalizationDataMgr() | |
} | ||
} | ||
|
||
//// ICreateLocalizedElement ///////////////////////////////////////// | ||
|
||
pfLocalizationDataMgr::localizedElement pfLocalizationDataMgr::ICreateLocalizedElement() | ||
{ | ||
int numLocales = plLocalization::GetNumLocales(); | ||
pfLocalizationDataMgr::localizedElement retVal; | ||
|
||
for (int curLocale = 0; curLocale <= numLocales; curLocale++) | ||
{ | ||
retVal[plLocalization::GetLanguageName((plLocalization::Language)curLocale)] = ""; | ||
} | ||
|
||
return retVal; | ||
} | ||
|
||
//// IGetCurrentLanguageName ///////////////////////////////////////// | ||
|
||
ST::string pfLocalizationDataMgr::IGetCurrentLanguageName() const | ||
{ | ||
return plLocalization::GetLanguageName(plLocalization::GetLanguage()); | ||
} | ||
|
||
//// IGetAllLanguageNames //////////////////////////////////////////// | ||
|
||
std::vector<ST::string> pfLocalizationDataMgr::IGetAllLanguageNames() const | ||
{ | ||
int numLocales = plLocalization::GetNumLocales(); | ||
std::vector<ST::string> retVal; | ||
|
||
for (int curLocale = 0; curLocale <= numLocales; curLocale++) | ||
{ | ||
ST::string name = plLocalization::GetLanguageName((plLocalization::Language)curLocale); | ||
retVal.push_back(name); | ||
} | ||
|
||
return retVal; | ||
} | ||
|
||
//// IConvertSubtitle //////////////////////////////////////////////// | ||
|
||
void pfLocalizationDataMgr::IConvertElement(const pfLocalizationDataMgr::element& elementInfo, const ST::string & curPath) | ||
|
@@ -1153,10 +1112,9 @@ bool pfLocalizationDataMgr::DeleteElement(const ST::string & name) | |
void pfLocalizationDataMgr::WriteDatabaseToDisk(const plFileName & path) const | ||
{ | ||
std::vector<ST::string> ageNames = GetAgeList(); | ||
std::vector<ST::string> languageNames = IGetAllLanguageNames(); | ||
for (const auto& curAge : ageNames) | ||
{ | ||
for (const auto& curLanguage : languageNames) | ||
for (const auto& curLanguage : plLocalization::GetAllLanguageNames()) | ||
{ | ||
plFileName locPath = plFileName::Join(path, ST::format("{}{}.loc", | ||
curAge, curLanguage)); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would we feel about ISO language codes (i.e.,
en
,fr
,de
,it
,es
, etc.) rather that names? That would open us to support region-specific localizations (such as spelling "Neighbourhood" properly inen-GB
)Although I guess that complicates the .loc files too, eh?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally we would use standard language codes everywhere instead of custom names, yeah. Migrating the existing .loc files would be quite painful though - it would be a big incompatible change to all existing content, which would break open PRs and require changes to other tools like Korman.