37 : languageName (
other.languageName), countryCodes (
other.countryCodes),
42LocalisedStrings& LocalisedStrings::operator= (
const LocalisedStrings&
other)
44 languageName =
other.languageName;
45 countryCodes =
other.countryCodes;
46 translations =
other.translations;
54 if (fallback !=
nullptr && ! translations.
containsKey (text))
55 return fallback->translate (text);
57 return translations.
getValue (text, text);
62 if (fallback !=
nullptr && ! translations.
containsKey (text))
70 #if JUCE_CHECK_MEMORY_LEAKS
93 auto t = text.getCharPointer() + startPos;
97 auto c = t.getAndAdvance();
99 if (c == 0 || (c ==
'"' &&
lastChar !=
'\\'))
111 return s.replace (
"\\\"",
"\"")
112 .replace (
"\\\'",
"\'")
113 .replace (
"\\t",
"\t")
114 .replace (
"\\r",
"\r")
115 .replace (
"\\n",
"\n");
119void LocalisedStrings::loadFromText (
const String&
fileContents,
bool ignoreCase)
126 for (
auto&
l : lines)
128 auto line =
l.trim();
130 if (line.startsWithChar (
'"'))
135 if (originalText.isNotEmpty())
145 else if (line.startsWithIgnoreCase (
"language:"))
149 else if (line.startsWithIgnoreCase (
"countries:"))
151 countryCodes.
addTokens (line.substring (10).trim(),
true);
Wraps a pointer to a null-terminated UTF-8 character string, and provides various methods to operate ...
Represents a local file or directory.
String loadFileAsString() const
Reads a file into memory as a string.
Automatically locks and unlocks a mutex object.
Used to convert strings to localised foreign-language versions.
static void setCurrentMappings(LocalisedStrings *newTranslations)
Selects the current set of mappings to be used by the system.
static String translateWithCurrentMappings(const String &text)
Tries to translate a string using the currently selected set of mappings.
String translate(const String &text) const
Attempts to look up a string and return its localised version.
static LocalisedStrings * getCurrentMappings()
Returns the currently selected set of mappings.
void addStrings(const LocalisedStrings &)
Adds and merges another set of translations into this set.
LocalisedStrings(const String &fileContents, bool ignoreCaseOfKeys)
Creates a set of translations from the text of a translation file.
void setFallback(LocalisedStrings *fallbackStrings)
Gives this object a set of strings to use as a fallback if a string isn't found.
void removeEmptyStrings(bool removeWhitespaceStrings=true)
Removes empty strings from the array.
void trim()
Deletes any whitespace characters from the starts and ends of all the strings.
int addTokens(StringRef stringToTokenise, bool preserveQuotedStrings)
Breaks up a string into tokens and adds them to this array.
void setIgnoresCase(bool shouldIgnoreCase)
Indicates whether to use a case-insensitive search when looking up a key string.
String getValue(StringRef, const String &defaultReturnValue) const
Finds the value corresponding to a key string.
bool containsKey(StringRef key) const noexcept
Returns true if the given key exists.
void set(const String &key, const String &value)
Adds or amends a key/value pair.
void minimiseStorageOverheads()
Reduces the amount of storage being used by the array.
void addArray(const StringPairArray &other)
Adds the items from another array to this one.
String trim() const
Returns a copy of this string with any whitespace characters removed from the start and end.
String substring(int startIndex, int endIndex) const
Returns a subsection of the string.
Type * createCopyIfNotNull(const Type *objectToCopy)
If a pointer is non-null, this returns a new copy of the object that it points to,...
wchar_t juce_wchar
A platform-independent 32-bit unicode character type.
JUCE_API String translate(const String &text)
Uses the LocalisedStrings class to translate the given string literal.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...