mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	Added 'translate missing' command for convenience
This commit is contained in:
		| @@ -185,12 +185,12 @@ void ClientCommandManager::handleRedrawCommand() | ||||
| 	GH.windows().totalRedraw(); | ||||
| } | ||||
|  | ||||
| void ClientCommandManager::handleTranslateGameCommand() | ||||
| void ClientCommandManager::handleTranslateGameCommand(bool onlyMissing) | ||||
| { | ||||
| 	std::map<std::string, std::map<std::string, std::string>> textsByMod; | ||||
| 	VLC->generaltexth->exportAllTexts(textsByMod); | ||||
| 	VLC->generaltexth->exportAllTexts(textsByMod, onlyMissing); | ||||
|  | ||||
| 	const boost::filesystem::path outPath = VCMIDirs::get().userExtractedPath() / "translation"; | ||||
| 	const boost::filesystem::path outPath = VCMIDirs::get().userExtractedPath() / ( onlyMissing ? "translationMissing" : "translation"); | ||||
| 	boost::filesystem::create_directories(outPath); | ||||
|  | ||||
| 	for(const auto & modEntry : textsByMod) | ||||
| @@ -267,7 +267,7 @@ void ClientCommandManager::handleTranslateMapsCommand() | ||||
| 	} | ||||
|  | ||||
| 	std::map<std::string, std::map<std::string, std::string>> textsByMod; | ||||
| 	VLC->generaltexth->exportAllTexts(textsByMod); | ||||
| 	VLC->generaltexth->exportAllTexts(textsByMod, false); | ||||
|  | ||||
| 	const boost::filesystem::path outPath = VCMIDirs::get().userExtractedPath() / "translation"; | ||||
| 	boost::filesystem::create_directories(outPath); | ||||
| @@ -598,7 +598,10 @@ void ClientCommandManager::processCommand(const std::string & message, bool call | ||||
| 		handleRedrawCommand(); | ||||
|  | ||||
| 	else if(message=="translate" || message=="translate game") | ||||
| 		handleTranslateGameCommand(); | ||||
| 		handleTranslateGameCommand(false); | ||||
|  | ||||
| 	else if(message=="translate missing") | ||||
| 		handleTranslateGameCommand(true); | ||||
|  | ||||
| 	else if(message=="translate maps") | ||||
| 		handleTranslateMapsCommand(); | ||||
|   | ||||
| @@ -46,7 +46,7 @@ class ClientCommandManager //take mantis #2292 issue about account if thinking a | ||||
| 	void handleRedrawCommand(); | ||||
|  | ||||
| 	// Extracts all translateable game texts into Translation directory, separating files on per-mod basis | ||||
| 	void handleTranslateGameCommand(); | ||||
| 	void handleTranslateGameCommand(bool onlyMissing); | ||||
|  | ||||
| 	// Extracts all translateable texts from maps and campaigns into Translation directory, separating files on per-mod basis | ||||
| 	void handleTranslateMapsCommand(); | ||||
|   | ||||
| @@ -121,6 +121,7 @@ Below a list of supported commands, with their arguments wrapped in `<>` | ||||
|  | ||||
| #### Extract commands | ||||
| `translate` - save game texts into json files | ||||
| `translate missing` - save untranslated game texts into json files | ||||
| `translate maps` - save map and campaign texts into json files | ||||
| `get config` - save game objects data into json files | ||||
| `get scripts` - dumps lua script stuff into files (currently inactive due to scripting disabled for default builds) | ||||
|   | ||||
| @@ -136,6 +136,8 @@ After that, start Launcher, switch to Help tab and open "log files directory". Y | ||||
|  | ||||
| If your mod also contains maps or campaigns that you want to translate, then use '/translate maps' command instead. | ||||
|  | ||||
| If you want to update existing translation, you can use '/translate missing' command that will export only strings that were not translated | ||||
|  | ||||
| ### Translating mod information | ||||
| In order to display information in Launcher in language selected by user add following block into your `mod.json`: | ||||
| ``` | ||||
|   | ||||
| @@ -446,8 +446,8 @@ void CModHandler::loadTranslation(const TModID & modName) | ||||
| 	JsonNode baseTranslation = JsonUtils::assembleFromFiles(mod.config["translations"]); | ||||
| 	JsonNode extraTranslation = JsonUtils::assembleFromFiles(mod.config[preferredLanguage]["translations"]); | ||||
|  | ||||
| 	VLC->generaltexth->loadTranslationOverrides(modName, baseTranslation); | ||||
| 	VLC->generaltexth->loadTranslationOverrides(modName, extraTranslation); | ||||
| 	VLC->generaltexth->loadTranslationOverrides(modName, modBaseLanguage, baseTranslation); | ||||
| 	VLC->generaltexth->loadTranslationOverrides(modName, preferredLanguage, extraTranslation); | ||||
| } | ||||
|  | ||||
| void CModHandler::load() | ||||
|   | ||||
| @@ -22,7 +22,7 @@ VCMI_LIB_NAMESPACE_BEGIN | ||||
|  | ||||
| std::recursive_mutex TextLocalizationContainer::globalTextMutex; | ||||
|  | ||||
| void TextLocalizationContainer::registerStringOverride(const std::string & modContext, const TextIdentifier & UID, const std::string & localized) | ||||
| void TextLocalizationContainer::registerStringOverride(const std::string & modContext, const TextIdentifier & UID, const std::string & localized, const std::string & language) | ||||
| { | ||||
| 	std::lock_guard globalLock(globalTextMutex); | ||||
|  | ||||
| @@ -42,6 +42,11 @@ void TextLocalizationContainer::registerStringOverride(const std::string & modCo | ||||
| 			entry.identifierModContext = modContext; | ||||
| 			entry.baseStringModContext = modContext; | ||||
| 		} | ||||
| 		else | ||||
| 		{ | ||||
| 			if (language == VLC->generaltexth->getPreferredLanguage()) | ||||
| 				entry.overriden = true; | ||||
| 		} | ||||
| 	} | ||||
| 	else | ||||
| 	{ | ||||
| @@ -127,10 +132,10 @@ void TextLocalizationContainer::registerString(const std::string & identifierMod | ||||
| 	} | ||||
| } | ||||
|  | ||||
| void TextLocalizationContainer::loadTranslationOverrides(const std::string & modContext, const JsonNode & config) | ||||
| void TextLocalizationContainer::loadTranslationOverrides(const std::string & modContext, const std::string & language, const JsonNode & config) | ||||
| { | ||||
| 	for(const auto & node : config.Struct()) | ||||
| 		registerStringOverride(modContext, node.first, node.second.String()); | ||||
| 		registerStringOverride(modContext, node.first, node.second.String(), language); | ||||
| } | ||||
|  | ||||
| bool TextLocalizationContainer::identifierExists(const TextIdentifier & UID) const | ||||
| @@ -140,15 +145,18 @@ bool TextLocalizationContainer::identifierExists(const TextIdentifier & UID) con | ||||
| 	return stringsLocalizations.count(UID.get()); | ||||
| } | ||||
|  | ||||
| void TextLocalizationContainer::exportAllTexts(std::map<std::string, std::map<std::string, std::string>> & storage) const | ||||
| void TextLocalizationContainer::exportAllTexts(std::map<std::string, std::map<std::string, std::string>> & storage, bool onlyMissing) const | ||||
| { | ||||
| 	std::lock_guard globalLock(globalTextMutex); | ||||
|  | ||||
| 	for (auto const & subContainer : subContainers) | ||||
| 		subContainer->exportAllTexts(storage); | ||||
| 		subContainer->exportAllTexts(storage, onlyMissing); | ||||
|  | ||||
| 	for (auto const & entry : stringsLocalizations) | ||||
| 	{ | ||||
| 		if (onlyMissing && entry.second.overriden) | ||||
| 			continue; | ||||
|  | ||||
| 		std::string textToWrite; | ||||
| 		std::string modName = entry.second.baseStringModContext; | ||||
|  | ||||
|   | ||||
| @@ -32,6 +32,8 @@ protected: | ||||
| 		/// Different from identifierModContext if mod has modified object from another mod (e.g. rebalance mods) | ||||
| 		std::string baseStringModContext; | ||||
|  | ||||
| 		bool overriden = false; | ||||
|  | ||||
| 		template <typename Handler> | ||||
| 		void serialize(Handler & h) | ||||
| 		{ | ||||
| @@ -47,7 +49,7 @@ protected: | ||||
| 	std::vector<const TextLocalizationContainer *> subContainers; | ||||
|  | ||||
| 	/// add selected string to internal storage as high-priority strings | ||||
| 	void registerStringOverride(const std::string & modContext, const TextIdentifier & UID, const std::string & localized); | ||||
| 	void registerStringOverride(const std::string & modContext, const TextIdentifier & UID, const std::string & localized, const std::string & language); | ||||
|  | ||||
| 	std::string getModLanguage(const std::string & modContext); | ||||
|  | ||||
| @@ -57,7 +59,7 @@ protected: | ||||
| public: | ||||
| 	/// Loads translation from provided json | ||||
| 	/// Any entries loaded by this will have priority over texts registered normally | ||||
| 	void loadTranslationOverrides(const std::string & modContext, JsonNode const & file); | ||||
| 	void loadTranslationOverrides(const std::string & modContext, const std::string & language, JsonNode const & file); | ||||
|  | ||||
| 	/// add selected string to internal storage | ||||
| 	void registerString(const std::string & modContext, const TextIdentifier & UID, const JsonNode & localized); | ||||
| @@ -77,7 +79,7 @@ public: | ||||
|  | ||||
| 	/// Debug method, returns all currently stored texts | ||||
| 	/// Format: [mod ID][string ID] -> human-readable text | ||||
| 	void exportAllTexts(std::map<std::string, std::map<std::string, std::string>> & storage) const; | ||||
| 	void exportAllTexts(std::map<std::string, std::map<std::string, std::string>> & storage, bool onlyMissing) const; | ||||
|  | ||||
| 	/// Add or override subcontainer which can store identifiers | ||||
| 	void addSubContainer(const TextLocalizationContainer & container); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user