COMMON: Make TranslationManager reusable.
This makes it possible to reuse TranslationManager with different files.
This commit is contained in:
parent
937d5c4a98
commit
0d39e96f55
5 changed files with 24 additions and 16 deletions
|
@ -697,7 +697,7 @@ extern "C" int scummvm_main(int argc, const char * const argv[]) {
|
|||
#endif
|
||||
Common::SearchManager::destroy();
|
||||
#ifdef USE_TRANSLATION
|
||||
Common::TranslationManager::destroy();
|
||||
Common::MainTranslationManager::destroy();
|
||||
#endif
|
||||
MusicManager::destroy();
|
||||
Graphics::CursorManager::destroy();
|
||||
|
|
|
@ -39,14 +39,14 @@
|
|||
|
||||
namespace Common {
|
||||
|
||||
DECLARE_SINGLETON(TranslationManager);
|
||||
DECLARE_SINGLETON(MainTranslationManager);
|
||||
|
||||
bool operator<(const TLanguage &l, const TLanguage &r) {
|
||||
return l.name < r.name;
|
||||
}
|
||||
|
||||
TranslationManager::TranslationManager() : _currentLang(-1) {
|
||||
loadTranslationsInfoDat();
|
||||
TranslationManager::TranslationManager(const Common::String &fileName) : _currentLang(-1) {
|
||||
loadTranslationsInfoDat(fileName);
|
||||
|
||||
// Set the default language
|
||||
setLanguage("");
|
||||
|
@ -230,7 +230,7 @@ bool TranslationManager::openTranslationsFile(File &inFile) {
|
|||
|
||||
// Then try to open it using the SearchMan.
|
||||
ArchiveMemberList fileList;
|
||||
SearchMan.listMatchingMembers(fileList, "translations.dat");
|
||||
SearchMan.listMatchingMembers(fileList, _translationsFileName);
|
||||
for (ArchiveMemberList::iterator it = fileList.begin(); it != fileList.end(); ++it) {
|
||||
ArchiveMember const &m = **it;
|
||||
SeekableReadStream *const stream = m.createReadStream();
|
||||
|
@ -251,7 +251,7 @@ bool TranslationManager::openTranslationsFile(const FSNode &node, File &inFile,
|
|||
// Check if we can find the file in this directory
|
||||
// Since File::open(FSNode) makes all the needed tests, it is not really
|
||||
// necessary to make them here. But it avoid printing warnings.
|
||||
FSNode fileNode = node.getChild("translations.dat");
|
||||
FSNode fileNode = node.getChild(_translationsFileName);
|
||||
if (fileNode.exists() && fileNode.isReadable() && !fileNode.isDirectory()) {
|
||||
if (inFile.open(fileNode)) {
|
||||
if (checkHeader(inFile))
|
||||
|
@ -278,10 +278,11 @@ bool TranslationManager::openTranslationsFile(const FSNode &node, File &inFile,
|
|||
return false;
|
||||
}
|
||||
|
||||
void TranslationManager::loadTranslationsInfoDat() {
|
||||
void TranslationManager::loadTranslationsInfoDat(const Common::String &name) {
|
||||
File in;
|
||||
_translationsFileName = name;
|
||||
if (!openTranslationsFile(in)) {
|
||||
warning("You are missing a valid 'translations.dat' file. GUI translation will not be available");
|
||||
warning("You are missing a valid '%s' file. GUI translation will not be available", name.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -85,14 +85,14 @@ struct PoMessageEntry {
|
|||
/**
|
||||
* Message translation manager.
|
||||
*/
|
||||
class TranslationManager : public Singleton<TranslationManager> {
|
||||
class TranslationManager : public NonCopyable {
|
||||
public:
|
||||
/**
|
||||
* Constructor that sets the current language to the default language.
|
||||
*
|
||||
* The default language is the detected system language.
|
||||
*/
|
||||
TranslationManager();
|
||||
TranslationManager(const Common::String &fileName);
|
||||
~TranslationManager();
|
||||
|
||||
/**
|
||||
|
@ -221,7 +221,7 @@ private:
|
|||
/**
|
||||
* Load the list of languages from the translations.dat file.
|
||||
*/
|
||||
void loadTranslationsInfoDat();
|
||||
void loadTranslationsInfoDat(const Common::String &name);
|
||||
|
||||
/**
|
||||
* Load the translation for the given language from the translations.dat file.
|
||||
|
@ -242,13 +242,20 @@ private:
|
|||
Array<PoMessageEntry> _currentTranslationMessages;
|
||||
String _currentCharset;
|
||||
int _currentLang;
|
||||
Common::String _translationsFileName;
|
||||
};
|
||||
|
||||
class MainTranslationManager : public TranslationManager, public Singleton<MainTranslationManager> {
|
||||
public:
|
||||
MainTranslationManager() : TranslationManager("translations.dat") {}
|
||||
~MainTranslationManager() {}
|
||||
};
|
||||
|
||||
/** @} */
|
||||
|
||||
} // End of namespace Common
|
||||
|
||||
#define TransMan Common::TranslationManager::instance()
|
||||
#define TransMan Common::MainTranslationManager::instance()
|
||||
|
||||
#define _(str) TransMan.getTranslation(str)
|
||||
#define _c(str, context) TransMan.getTranslation(str, context)
|
||||
|
|
|
@ -110,7 +110,7 @@ int main(int argc, char *argv[]) {
|
|||
PoMessageList messageIds;
|
||||
std::vector<PoMessageEntryList *> translations;
|
||||
int numLangs = 0;
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
for (int i = 2; i < argc; ++i) {
|
||||
// Check file extension
|
||||
int len = strlen(argv[i]);
|
||||
if (scumm_stricmp(argv[i] + len - 2, "po") == 0) {
|
||||
|
@ -124,7 +124,7 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
if (!numLangs) {
|
||||
fprintf(stderr, "ERROR: No valid translation files\n");
|
||||
fprintf(stderr, "usage: create_translations lang1.po [lang2.po ...]\n");
|
||||
fprintf(stderr, "usage: create_translations OUTPUT lang1.po [lang2.po ...]\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -147,7 +147,7 @@ int main(int argc, char *argv[]) {
|
|||
// for (i = 0; i < DATAALIGNMENT; i++)
|
||||
// padBuf[i] = 0;
|
||||
|
||||
outFile = fopen("translations.dat", "wb");
|
||||
outFile = fopen(argv[1], "wb");
|
||||
|
||||
// Write header
|
||||
fwrite("TRANSLATIONS", 12, 1, outFile);
|
||||
|
|
|
@ -36,7 +36,7 @@ updatepot:
|
|||
fi;
|
||||
|
||||
translations-dat: devtools/create_translations
|
||||
devtools/create_translations/create_translations $(POFILES)
|
||||
devtools/create_translations/create_translations translations.dat $(POFILES)
|
||||
mv translations.dat $(srcdir)/gui/themes/
|
||||
|
||||
update-translations: updatepot $(POFILES) translations-dat
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue