From 9bef7e95d064e1e82467e57df6673b149b77839f Mon Sep 17 00:00:00 2001
From: Vadim ProductEngine <vsavchuk@productengine.com>
Date: Fri, 29 Jul 2011 05:20:54 +0300
Subject: [PATCH] STORM-1436 FIXED Broken localization of "Contents" and "New
 Script" items in the Contents tab of Build Tools.

The bug happened when the translations contained non-ASCII characters.

Reason: Names of inventory items are limited to ASCII characters.
Fix: Leave names in English, localize them when displaying (on the fly).

The fix only affects object's inventory (i.e. not agent inventory).
---
 indra/newview/llpanelcontents.cpp        |  2 +-
 indra/newview/llpanelobjectinventory.cpp | 56 +++++++++++++++++-------
 indra/newview/llviewerobject.cpp         |  4 +-
 3 files changed, 42 insertions(+), 20 deletions(-)

diff --git a/indra/newview/llpanelcontents.cpp b/indra/newview/llpanelcontents.cpp
index bf3bf38863e..a64b4ec94d5 100644
--- a/indra/newview/llpanelcontents.cpp
+++ b/indra/newview/llpanelcontents.cpp
@@ -172,7 +172,7 @@ void LLPanelContents::onClickNewScript(void *userdata)
 				LLUUID::null,
 				LLAssetType::AT_LSL_TEXT,
 				LLInventoryType::IT_LSL,
-				LLTrans::getString("PanelContentsNewScript"),
+				"New Script",
 				desc,
 				LLSaleInfo::DEFAULT,
 				LLInventoryItemFlags::II_FLAGS_NONE,
diff --git a/indra/newview/llpanelobjectinventory.cpp b/indra/newview/llpanelobjectinventory.cpp
index e3b61f695a3..83ba8afbfca 100644
--- a/indra/newview/llpanelobjectinventory.cpp
+++ b/indra/newview/llpanelobjectinventory.cpp
@@ -83,6 +83,7 @@ class LLTaskInvFVBridge : public LLFolderViewEventListener
 	LLAssetType::EType mAssetType;	
 	LLInventoryType::EType mInventoryType;
 
+	LLInventoryObject* findInvObject() const;
 	LLInventoryItem* findItem() const;
 
 public:
@@ -162,16 +163,22 @@ LLTaskInvFVBridge::LLTaskInvFVBridge(
 	}
 }
 
-LLInventoryItem* LLTaskInvFVBridge::findItem() const
+LLInventoryObject* LLTaskInvFVBridge::findInvObject() const
 {
 	LLViewerObject* object = gObjectList.findObject(mPanel->getTaskUUID());
-	if(object)
+	if (object)
 	{
-		return dynamic_cast<LLInventoryItem*>(object->getInventoryObject(mUUID));
+		return object->getInventoryObject(mUUID);
 	}
 	return NULL;
 }
 
+
+LLInventoryItem* LLTaskInvFVBridge::findItem() const
+{
+	return dynamic_cast<LLInventoryItem*>(findInvObject());
+}
+
 void LLTaskInvFVBridge::showProperties()
 {
 	show_task_item_profile(mUUID, mPanel->getTaskUUID());
@@ -295,21 +302,15 @@ const std::string& LLTaskInvFVBridge::getDisplayName() const
 
 	if(item)
 	{
-		if(item->getParentUUID().isNull())
-		{
-			if(item->getName() == "Contents")
-			{
-				mDisplayName.assign(LLTrans::getString("ViewerObjectContents"));
-			}
-			else
-			{
-				mDisplayName.assign(item->getName());
-			}
-		}
-		else
+		mDisplayName.assign(item->getName());
+
+		// Localize "New Script", "New Script 1", "New Script 2", etc.
+		if (item->getType() == LLAssetType::AT_LSL_TEXT &&
+			LLStringUtil::startsWith(item->getName(), "New Script"))
 		{
-			mDisplayName.assign(item->getName());
+			LLStringUtil::replaceString(mDisplayName, "New Script", LLTrans::getString("PanelContentsNewScript"));
 		}
+
 		const LLPermissions& perm(item->getPermissions());
 		BOOL copy = gAgent.allowOperation(PERM_COPY, perm, GP_OBJECT_MANIPULATE);
 		BOOL mod  = gAgent.allowOperation(PERM_MODIFY, perm, GP_OBJECT_MANIPULATE);
@@ -700,7 +701,7 @@ class LLTaskCategoryBridge : public LLTaskInvFVBridge
 		const std::string& name);
 
 	virtual LLUIImagePtr getIcon() const;
-	virtual const std::string& getDisplayName() const { return getName(); }
+	virtual const std::string& getDisplayName() const;
 	virtual BOOL isItemRenameable() const;
 	// virtual BOOL isItemCopyable() const { return FALSE; }
 	virtual BOOL renameItem(const std::string& new_name);
@@ -728,6 +729,27 @@ LLUIImagePtr LLTaskCategoryBridge::getIcon() const
 	return LLUI::getUIImage("Inv_FolderClosed");
 }
 
+// virtual
+const std::string& LLTaskCategoryBridge::getDisplayName() const
+{
+	LLInventoryObject* cat = findInvObject();
+
+	if (cat)
+	{
+		// Localize "Contents" folder.
+		if (cat->getParentUUID().isNull() && cat->getName() == "Contents")
+		{
+			mDisplayName.assign(LLTrans::getString("ViewerObjectContents"));
+		}
+		else
+		{
+			mDisplayName.assign(cat->getName());
+		}
+	}
+
+	return mDisplayName;
+}
+
 BOOL LLTaskCategoryBridge::isItemRenameable() const
 {
 	return FALSE;
diff --git a/indra/newview/llviewerobject.cpp b/indra/newview/llviewerobject.cpp
index 972993202a7..b187fdca6f6 100644
--- a/indra/newview/llviewerobject.cpp
+++ b/indra/newview/llviewerobject.cpp
@@ -2660,7 +2660,7 @@ void LLViewerObject::processTaskInv(LLMessageSystem* msg, void** user_data)
 		LLPointer<LLInventoryObject> obj;
 		obj = new LLInventoryObject(object->mID, LLUUID::null,
 									LLAssetType::AT_CATEGORY,
-									LLTrans::getString("ViewerObjectContents").c_str());
+									"Contents");
 		object->mInventory->push_front(obj);
 		object->doInventoryCallback();
 		delete ft;
@@ -2727,7 +2727,7 @@ void LLViewerObject::loadTaskInvFile(const std::string& filename)
 			{
 				LLPointer<LLInventoryObject> inv = new LLInventoryObject;
 				inv->importLegacyStream(ifs);
-				inv->rename(LLTrans::getString("ViewerObjectContents").c_str());
+				inv->rename("Contents");
 				mInventory->push_front(inv);
 			}
 			else
-- 
GitLab