28 loadFromText (fileContents, ignoreCase);
37 : languageName (other.languageName), countryCodes (other.countryCodes),
38 translations (other.translations), fallback (createCopyIfNotNull (other.fallback.get()))
44 languageName = other.languageName;
45 countryCodes = other.countryCodes;
46 translations = other.translations;
47 fallback.reset (createCopyIfNotNull (other.fallback.get()));
58 if (fallback !=
nullptr && ! translations.
containsKey (text))
59 return fallback->translate (text);
61 return translations.
getValue (text, text);
66 if (fallback !=
nullptr && ! translations.
containsKey (text))
67 return fallback->translate (text, resultIfNotFound);
69 return translations.
getValue (text, resultIfNotFound);
74 #if JUCE_CHECK_MEMORY_LEAKS 80 struct LeakAvoidanceTrick
88 LeakAvoidanceTrick leakAvoidanceTrick;
92 std::unique_ptr<LocalisedStrings> currentMappings;
94 static int findCloseQuote (
const String& text,
int startPos)
96 juce_wchar lastChar = 0;
101 auto c = t.getAndAdvance();
103 if (c == 0 || (c ==
'"' && lastChar !=
'\\'))
115 return s.
replace (
"\\\"",
"\"")
123 void LocalisedStrings::loadFromText (
const String& fileContents,
bool ignoreCase)
125 translations.setIgnoresCase (ignoreCase);
130 for (
auto& l : lines)
132 auto line = l.trim();
134 if (line.startsWithChar (
'"'))
136 auto closeQuote = findCloseQuote (line, 1);
137 auto originalText = unescapeString (line.substring (1, closeQuote));
139 if (originalText.isNotEmpty())
141 auto openingQuote = findCloseQuote (line, closeQuote + 1);
142 closeQuote = findCloseQuote (line, openingQuote + 1);
143 auto newText = unescapeString (line.substring (openingQuote + 1, closeQuote));
145 if (newText.isNotEmpty())
146 translations.set (originalText, newText);
149 else if (line.startsWithIgnoreCase (
"language:"))
151 languageName = line.substring (9).trim();
153 else if (line.startsWithIgnoreCase (
"countries:"))
155 countryCodes.addTokens (line.substring (10).trim(),
true);
157 countryCodes.removeEmptyStrings();
161 translations.minimiseStorageOverheads();
166 jassert (languageName == other.languageName);
167 jassert (countryCodes == other.countryCodes);
169 translations.addArray (other.translations);
181 currentMappings.reset (newTranslations);
186 return currentMappings.get();
201 return mappings->translate (text, resultIfNotFound);
203 return resultIfNotFound;
String translate(const String &text) const
void setFallback(LocalisedStrings *fallbackStrings)
static void setCurrentMappings(LocalisedStrings *newTranslations)
CharPointerType getCharPointer() const noexcept
int addLines(StringRef stringToBreakUp)
String getValue(StringRef, const String &defaultReturnValue) const
LocalisedStrings(const String &fileContents, bool ignoreCaseOfKeys)
static LocalisedStrings * getCurrentMappings()
String loadFileAsString() const
static String translateWithCurrentMappings(const String &text)
void addStrings(const LocalisedStrings &)
String replace(StringRef stringToReplace, StringRef stringToInsertInstead, bool ignoreCase=false) const
bool containsKey(StringRef key) const noexcept