Skip to content

Commit

Permalink
AGS: Allow setting the game language from the command line
Browse files Browse the repository at this point in the history
It is now possible to set the game language in AGS from the command
line, using the "--language" parameter. If a language is set from the
command line, it overrides the one set from the GUI.
Original implementation was done in PR scummvm#5151
  • Loading branch information
bluegr committed Sep 24, 2024
1 parent 5043f91 commit bd757ea
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 10 deletions.
12 changes: 3 additions & 9 deletions engines/ags/dialogs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,11 @@ AGSOptionsWidget::AGSOptionsWidget(GuiObject *boss, const Common::String &name,
_langPopUp = new GUI::PopUpWidget(widgetsBoss(), _dialogLayout + ".translation");
_langPopUp->appendEntry(_("<default>"), (uint32) - 1);

Common::Path path = ConfMan.getPath("path", _domain);
Common::FSDirectory dir(path);
Common::ArchiveMemberList traFileList;
dir.listMatchingMembers(traFileList, "*.tra");
_traFileNames = AGSMetaEngine::getGameTranslations(_domain);

int i = 0;
for (Common::ArchiveMemberList::iterator iter = traFileList.begin(); iter != traFileList.end(); ++iter) {
Common::String traFileName = (*iter)->getName();
traFileName.erase(traFileName.size() - 4); // remove .tra extension
_traFileNames.push_back(traFileName);
_langPopUp->appendEntry(traFileName, i++);
for (Common::StringArray::iterator iter = _traFileNames.begin(); iter != _traFileNames.end(); ++iter) {
_langPopUp->appendEntry(*iter, i++);
}

// Override game save management
Expand Down
31 changes: 30 additions & 1 deletion engines/ags/engine/main/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
#include "ags/shared/util/text_stream_reader.h"
#include "ags/shared/util/path.h"
#include "ags/shared/util/string_utils.h"
#include "ags/metaengine.h"
#include "common/config-manager.h"
#include "common/language.h"

namespace AGS3 {

Expand Down Expand Up @@ -321,7 +323,34 @@ void apply_config(const ConfigTree &cfg) {

// Translation / localization
Common::String translation;
if (ConfMan.getActiveDomain()->tryGetVal("translation", translation) && !translation.empty())

if (!ConfMan.get("language").empty() && ConfMan.isKeyTemporary("language")) {
// Map the language defined in the command-line "language" option to its description
Common::Language lang = Common::parseLanguage(ConfMan.get("language"));

if (lang != Common::Language::UNK_LANG) {
Common::String translationCode = Common::getLanguageCode(lang);
translationCode.toLowercase();
translation = Common::getLanguageDescription(lang);
translation.toLowercase();

// Check if the game actually has such a translation, and set it if it does
// The name of translation files can be anything, but in general they are one of:
// - English name of the language, for example French.tra or Spanish.tra (covered)
// - Translated name of the language, for example polsky.tra or francais.tra (not covered)
// - The language code, for example FR.tra or DE.tra (covered)
// - And these can be combined with a prefix or suffix, for example Nelly_Polish.tra, english2.tra (covered)
Common::StringArray traFileNames = AGSMetaEngine::getGameTranslations(ConfMan.getActiveDomainName());
for (Common::StringArray::iterator iter = traFileNames.begin(); iter != traFileNames.end(); ++iter) {
Common::String traFileName = *iter;
traFileName.toLowercase();
if (traFileName.contains(translation) || traFileName.equals(translationCode)) {
_GP(usetup).translation = *iter;
break;
}
}
}
} else if (ConfMan.getActiveDomain()->tryGetVal("translation", translation) && !translation.empty())
_GP(usetup).translation = translation;
else
_GP(usetup).translation = CfgReadString(cfg, "language", "translation");
Expand Down
16 changes: 16 additions & 0 deletions engines/ags/metaengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,22 @@ const Common::AchievementDescriptionList* AGSMetaEngine::getAchievementDescripti
return AGS::achievementDescriptionList;
}

Common::StringArray AGSMetaEngine::getGameTranslations(const Common::String &domain) {
Common::Path path = ConfMan.getPath("path", domain);
Common::FSDirectory dir(path);
Common::ArchiveMemberList traFileList;
dir.listMatchingMembers(traFileList, "*.tra");
Common::StringArray traFileNames;

for (Common::ArchiveMemberList::iterator iter = traFileList.begin(); iter != traFileList.end(); ++iter) {
Common::String traFileName = (*iter)->getName();
traFileName.erase(traFileName.size() - 4); // remove .tra extension
traFileNames.push_back(traFileName);
}

return traFileNames;
}

#if PLUGIN_ENABLED_DYNAMIC(AGS)
REGISTER_PLUGIN_DYNAMIC(AGS, PLUGIN_TYPE_ENGINE, AGSMetaEngine);
#else
Expand Down
2 changes: 2 additions & 0 deletions engines/ags/metaengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ class AGSMetaEngine : public AdvancedMetaEngine<AGS::AGSGameDescription> {
void removeSaveState(const char *target, int slot) const override;

const Common::AchievementDescriptionList *getAchievementDescriptionList() const override;

static Common::StringArray getGameTranslations(const Common::String &domain);
};

#endif

0 comments on commit bd757ea

Please sign in to comment.