Skip to content

Commit 1949bb6

Browse files
committed
Set name to custom when it changes.
1 parent b2c3105 commit 1949bb6

9 files changed

Lines changed: 64 additions & 5 deletions

File tree

‎Sources/NodeEngine/NE_Localization.cpp‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
namespace NE
55
{
66

7+
static NonLocalizedCollector* nonLocalizedCollector = nullptr;
8+
79
DictionarySource::DictionarySource ()
810
{
911

@@ -51,12 +53,37 @@ std::wstring Dictionary::GetLocalizedString (const std::wstring& id) const
5153
return dictionary.at (id);
5254
}
5355

56+
NonLocalizedCollector::NonLocalizedCollector ()
57+
{
58+
59+
}
60+
61+
NonLocalizedCollector::~NonLocalizedCollector ()
62+
{
63+
64+
}
65+
66+
NonLocalizedCollectorGuard::NonLocalizedCollectorGuard (NonLocalizedCollector* collector)
67+
{
68+
SetNonLocalizedCollector (collector);
69+
}
70+
71+
NonLocalizedCollectorGuard::~NonLocalizedCollectorGuard ()
72+
{
73+
SetNonLocalizedCollector (nullptr);
74+
}
75+
5476
static Dictionary& GetGlobalDictionary ()
5577
{
5678
static Dictionary globalDictionary;
5779
return globalDictionary;
5880
}
5981

82+
void SetNonLocalizedCollector (NonLocalizedCollector* collector)
83+
{
84+
nonLocalizedCollector = collector;
85+
}
86+
6087
bool FillDictionary (Dictionary& dictionary, DictionarySource& source)
6188
{
6289
dictionary.Clear ();
@@ -88,6 +115,11 @@ bool FillDictionary (DictionarySource& source)
88115
std::wstring LocalizeString (const std::wstring& str)
89116
{
90117
const Dictionary& globalDictionary = GetGlobalDictionary ();
118+
if (nonLocalizedCollector != nullptr) {
119+
if (!globalDictionary.HasLocalizedString (str)) {
120+
nonLocalizedCollector->NonLocalizedStringFound (str);
121+
}
122+
}
91123
return LocalizeString (globalDictionary, str);
92124
}
93125

‎Sources/NodeEngine/NE_Localization.hpp‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,22 @@ class Dictionary
3434
std::unordered_map<std::wstring, std::wstring> dictionary;
3535
};
3636

37+
class NonLocalizedCollector
38+
{
39+
public:
40+
NonLocalizedCollector ();
41+
virtual ~NonLocalizedCollector ();
42+
43+
virtual void NonLocalizedStringFound (const std::wstring& str) = 0;
44+
};
45+
46+
class NonLocalizedCollectorGuard
47+
{
48+
public:
49+
NonLocalizedCollectorGuard (NonLocalizedCollector* collector);
50+
~NonLocalizedCollectorGuard ();
51+
};
52+
3753
template<typename... Args>
3854
std::wstring FormatString (const std::wstring& format, Args... args)
3955
{
@@ -42,6 +58,8 @@ std::wstring FormatString (const std::wstring& format, Args... args)
4258
return std::wstring (resultString);
4359
}
4460

61+
void SetNonLocalizedCollector (NonLocalizedCollector* collector);
62+
4563
bool FillDictionary (Dictionary& dictionary, DictionarySource& source);
4664
std::wstring LocalizeString (const Dictionary& dictionary, const std::wstring& str);
4765

‎Sources/NodeEngine/NE_String.cpp‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ String::String (const std::wstring& strValue) :
1313

1414
void String::SetCustom (const std::wstring& customValue)
1515
{
16+
if (!isCustom && customValue == GetLocalized ()) {
17+
return;
18+
}
1619
strValue = customValue;
1720
isCustom = true;
1821
}

‎Sources/NodeEngine/NE_String.hpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class String
1313
SERIALIZABLE;
1414

1515
public:
16-
String (const std::wstring& strValue);
16+
explicit String (const std::wstring& strValue);
1717

1818
void SetCustom (const std::wstring& customValue);
1919
std::wstring GetLocalized () const;

‎Sources/NodeEngineTest/LocalizationTest.cpp‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,17 @@ TEST (StringLocalizationTest)
143143
ASSERT (appleString.GetLocalized (dictionary) == L"alma");
144144
ASSERT (lemonString.GetLocalized (dictionary) == L"citrom");
145145

146+
appleString.SetCustom (L"apple");
147+
ASSERT (appleString.GetLocalized (dictionary) == L"alma");
148+
146149
appleString.SetCustom (L"banana");
147150
ASSERT (appleString.GetLocalized (dictionary) == L"banana");
148151

149152
appleString.SetCustom (L"lemon");
150153
ASSERT (appleString.GetLocalized (dictionary) == L"lemon");
154+
155+
appleString.SetCustom (L"apple");
156+
ASSERT (appleString.GetLocalized (dictionary) == L"apple");
151157
}
152158

153159
}

‎Sources/NodeUIEngine/NUIE_UIInputSlot.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ std::wstring UIInputSlot::GetName () const
3030

3131
void UIInputSlot::SetName (const std::wstring& newName)
3232
{
33-
name = newName;
33+
name.SetCustom (newName);
3434
}
3535

3636
void UIInputSlot::RegisterCommands (InputSlotCommandRegistrator&) const

‎Sources/NodeUIEngine/NUIE_UINode.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ std::wstring UINode::GetNodeName () const
5151

5252
void UINode::SetNodeName (const std::wstring& newNodeName)
5353
{
54-
nodeName = newNodeName;
54+
nodeName.SetCustom (newNodeName);
5555
}
5656

5757
const Point& UINode::GetNodePosition () const

‎Sources/NodeUIEngine/NUIE_UINodeGroup.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ std::wstring UINodeGroup::GetName () const
7070

7171
void UINodeGroup::SetName (const std::wstring& newName)
7272
{
73-
name = newName;
73+
name.SetCustom (newName);
7474
InvalidateGroupDrawing ();
7575
}
7676

‎Sources/NodeUIEngine/NUIE_UIOutputSlot.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ std::wstring UIOutputSlot::GetName () const
3030

3131
void UIOutputSlot::SetName (const std::wstring& newName)
3232
{
33-
name = newName;
33+
name.SetCustom (newName);
3434
}
3535

3636
void UIOutputSlot::RegisterCommands (OutputSlotCommandRegistrator&) const

0 commit comments

Comments
 (0)