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.
Original implementation was done in PR scummvm#5151
  • Loading branch information
bluegr committed Sep 22, 2024
1 parent d7a6701 commit e04c0da
Show file tree
Hide file tree
Showing 4 changed files with 41 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
21 changes: 20 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 @@ -323,7 +325,24 @@ void apply_config(const ConfigTree &cfg) {
Common::String translation;
if (ConfMan.getActiveDomain()->tryGetVal("translation", translation) && !translation.empty())
_GP(usetup).translation = translation;
else
else 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) {
translation = Common::getLanguageDescription(lang);
translation.toLowercase();
translation.setChar(toupper(translation[0]), 0);
}

// Check if the game actually has such a translation, and set it if it does
Common::StringArray traFileNames = AGSMetaEngine::getGameTranslations(ConfMan.getActiveDomainName());
for (Common::StringArray::iterator iter = traFileNames.begin(); iter != traFileNames.end(); ++iter) {
if (translation.equalsIgnoreCase(*iter)) {
_GP(usetup).translation = translation;
break;
}
}
} else
_GP(usetup).translation = CfgReadString(cfg, "language", "translation");

// Resource caches and options
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 e04c0da

Please sign in to comment.