[Scummvm-git-logs] scummvm master -> 852006a9754141b2e386d1e48388b192dae8db08

bluegr noreply at scummvm.org
Wed Sep 25 13:23:51 UTC 2024


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
852006a975 AGS: Allow setting the game language from the command line


Commit: 852006a9754141b2e386d1e48388b192dae8db08
    https://github.com/scummvm/scummvm/commit/852006a9754141b2e386d1e48388b192dae8db08
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2024-09-25T16:23:47+03:00

Commit Message:
AGS: Allow setting the game language from the command line

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 #5151

Changed paths:
    engines/ags/dialogs.cpp
    engines/ags/engine/main/config.cpp
    engines/ags/metaengine.cpp
    engines/ags/metaengine.h


diff --git a/engines/ags/dialogs.cpp b/engines/ags/dialogs.cpp
index e852793b0b9..8ba012be6a2 100644
--- a/engines/ags/dialogs.cpp
+++ b/engines/ags/dialogs.cpp
@@ -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
diff --git a/engines/ags/engine/main/config.cpp b/engines/ags/engine/main/config.cpp
index 93724bb06b0..311d590c5e0 100644
--- a/engines/ags/engine/main/config.cpp
+++ b/engines/ags/engine/main/config.cpp
@@ -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 {
 
@@ -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");
diff --git a/engines/ags/metaengine.cpp b/engines/ags/metaengine.cpp
index 3dc8085eaf7..b1c13a67cf5 100644
--- a/engines/ags/metaengine.cpp
+++ b/engines/ags/metaengine.cpp
@@ -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
diff --git a/engines/ags/metaengine.h b/engines/ags/metaengine.h
index 805cfeadb1d..8d45ea2332b 100644
--- a/engines/ags/metaengine.h
+++ b/engines/ags/metaengine.h
@@ -80,6 +80,8 @@ public:
 	void removeSaveState(const char *target, int slot) const override;
 
 	const Common::AchievementDescriptionList *getAchievementDescriptionList() const override;
+
+	static Common::StringArray getGameTranslations(const Common::String &domain);
 };
 
 #endif




More information about the Scummvm-git-logs mailing list