Browse Source

Fix incorrect warnings about missing translations

Ivan Savenko 2 years ago
parent
commit
95dd4b3ffb
2 changed files with 16 additions and 4 deletions
  1. 12 0
      lib/CGeneralTextHandler.cpp
  2. 4 4
      lib/CGeneralTextHandler.h

+ 12 - 0
lib/CGeneralTextHandler.cpp

@@ -313,6 +313,18 @@ void CGeneralTextHandler::registerStringOverride(const std::string & modContext,
 	assert(!modContext.empty());
 	assert(!modContext.empty());
 	assert(!language.empty());
 	assert(!language.empty());
 
 
+	std::string baseModLanguage = getModLanguage(modContext);
+
+	if (baseModLanguage != language)
+	{
+		// this is translation - only add text to existing strings, do not register new ones
+		if (stringsLocalizations.count(UID.get()) == 0)
+		{
+			logMod->warn("Unknown string '%s' in mod '%s' for language '%s'. Ignoring", UID.get(), modContext, language);
+			return;
+		}
+	}
+
 	// NOTE: implicitly creates entry, intended - strings added by vcmi (and potential UI mods) are not registered anywhere at the moment
 	// NOTE: implicitly creates entry, intended - strings added by vcmi (and potential UI mods) are not registered anywhere at the moment
 	auto & entry = stringsLocalizations[UID.get()];
 	auto & entry = stringsLocalizations[UID.get()];
 
 

+ 4 - 4
lib/CGeneralTextHandler.h

@@ -141,8 +141,11 @@ class DLL_LINKAGE CGeneralTextHandler
 	std::vector<size_t> scenariosCountPerCampaign;
 	std::vector<size_t> scenariosCountPerCampaign;
 
 
 	std::string getModLanguage(const std::string & modContext);
 	std::string getModLanguage(const std::string & modContext);
-public:
 
 
+	/// add selected string to internal storage as high-priority strings
+	void registerStringOverride(const std::string & modContext, const std::string & language, const TextIdentifier & UID, const std::string & localized);
+
+public:
 	/// validates translation of specified language for specified mod
 	/// validates translation of specified language for specified mod
 	/// returns true if localization is valid and complete
 	/// returns true if localization is valid and complete
 	/// any error messages will be written to log file
 	/// any error messages will be written to log file
@@ -155,9 +158,6 @@ public:
 	/// add selected string to internal storage
 	/// add selected string to internal storage
 	void registerString(const std::string & modContext, const TextIdentifier & UID, const std::string & localized);
 	void registerString(const std::string & modContext, const TextIdentifier & UID, const std::string & localized);
 
 
-	/// add selected string to internal storage as high-priority strings
-	void registerStringOverride(const std::string & modContext, const std::string & language, const TextIdentifier & UID, const std::string & localized);
-
 	// returns true if identifier with such name was registered, even if not translated to current language
 	// returns true if identifier with such name was registered, even if not translated to current language
 	// not required right now, can be added if necessary
 	// not required right now, can be added if necessary
 	// bool identifierExists( const std::string identifier) const;
 	// bool identifierExists( const std::string identifier) const;