Browse Source

Added a LocalisedString::setFallback() method.

tags/2021-05-28
jules 12 years ago
parent
commit
ab053c5503
4 changed files with 29 additions and 2 deletions
  1. +15
    -2
      modules/juce_core/text/juce_LocalisedStrings.cpp
  2. +7
    -0
      modules/juce_core/text/juce_LocalisedStrings.h
  3. +5
    -0
      modules/juce_core/text/juce_StringPairArray.cpp
  4. +2
    -0
      modules/juce_core/text/juce_StringPairArray.h

+ 15
- 2
modules/juce_core/text/juce_LocalisedStrings.cpp View File

@@ -43,11 +43,17 @@ LocalisedStrings::~LocalisedStrings()
//==============================================================================
String LocalisedStrings::translate (const String& text) const
{
if (fallback != nullptr && ! translations.containsKey (text))
return fallback->translate (text);
return translations.getValue (text, text);
}
String LocalisedStrings::translate (const String& text, const String& resultIfNotFound) const
{
if (fallback != nullptr && ! translations.containsKey (text))
return fallback->translate (text, resultIfNotFound);
return translations.getValue (text, resultIfNotFound);
}
@@ -73,7 +79,7 @@ namespace
SpinLock currentMappingsLock;
ScopedPointer<LocalisedStrings> currentMappings;
int findCloseQuote (const String& text, int startPos)
static int findCloseQuote (const String& text, int startPos)
{
juce_wchar lastChar = 0;
String::CharPointerType t (text.getCharPointer() + startPos);
@@ -92,7 +98,7 @@ namespace
return startPos;
}
String unescapeString (const String& s)
static String unescapeString (const String& s)
{
return s.replace ("\\\"", "\"")
.replace ("\\\'", "\'")
@@ -141,6 +147,8 @@ void LocalisedStrings::loadFromText (const String& fileContents, bool ignoreCase
countryCodes.removeEmptyStrings();
}
}
translations.minimiseStorageOverheads();
}
void LocalisedStrings::addStrings (const LocalisedStrings& other)
@@ -151,6 +159,11 @@ void LocalisedStrings::addStrings (const LocalisedStrings& other)
translations.addArray (other.translations);
}
void LocalisedStrings::setFallback (LocalisedStrings* f)
{
fallback = f;
}
//==============================================================================
void LocalisedStrings::setCurrentMappings (LocalisedStrings* newTranslations)
{


+ 7
- 0
modules/juce_core/text/juce_LocalisedStrings.h View File

@@ -183,11 +183,18 @@ public:
*/
void addStrings (const LocalisedStrings&);
/** Gives this object a set of strings to use as a fallback if a string isn't found.
The object that is passed-in will be owned and deleted by this object
when no longer needed. It can be nullptr to clear the existing fallback object.
*/
void setFallback (LocalisedStrings* fallbackStrings);
private:
//==============================================================================
String languageName;
StringArray countryCodes;
StringPairArray translations;
ScopedPointer<LocalisedStrings> fallback;
void loadFromText (const String&, bool ignoreCase);


+ 5
- 0
modules/juce_core/text/juce_StringPairArray.cpp View File

@@ -78,6 +78,11 @@ String StringPairArray::getValue (StringRef key, const String& defaultReturnValu
return defaultReturnValue;
}
bool StringPairArray::containsKey (StringRef key) const noexcept
{
return keys.contains (key);
}
void StringPairArray::set (const String& key, const String& value)
{
const int i = keys.indexOf (key, ignoreCase);


+ 2
- 0
modules/juce_core/text/juce_StringPairArray.h View File

@@ -85,6 +85,8 @@ public:
*/
String getValue (StringRef, const String& defaultReturnValue) const;
/** Returns true if the given key exists. */
bool containsKey (StringRef key) const noexcept;
/** Returns a list of all keys in the array. */
const StringArray& getAllKeys() const noexcept { return keys; }


Loading…
Cancel
Save