LocalisedStrings and Resources

Hi there,

is there a way to load the translation file from resources and not from one external file ?

To load from regular file, external, i'm doing this way:

"
String filenameLang;
String filePath;
filenameLang = "pt_PT.lng";
filePath = File::getCurrentWorkingDirectory().getChildFile(filenameLang).getFullPathName();
File languageFile(filePath);
localisedStr = new LocalisedStrings(languageFile, false);
LocalisedStrings::setCurrentMappings(localisedStr);
LocalisedStrings(filenameLang, false);
"

How to do it if i already included the language file in my resources ?

Thanks for your support.

Paulo

Well yes.. didn't you notice that it has a constructor that takes a string instead of a file?

Hi Jules,

 

Can you give me a quick example on how to do it ?

Imagining that i have already a binary that is called "ptPT_lng" that is the translation file.

 

It was great !

Paulo

It's pretty trivial to do, unless I'm misunderstanding you?..

E.g. new LocalisedStrings (String (BinaryData::myTranslationFile_txt), false);

 

I already tried that way, but when starting my application, it give and exception and related with juce:string:

"jassert (t == nullptr || CharPointer_ASCII::isValidString (t, std::numeric_limits<int>::max()));"

and my file is well and in correct format and loaded as resource. Since i can load it externally without any problem.

 

 

Well yes - if your file was encoded as utf8 or utf16 then you'd probably want to call String::createStringFromData to create it.

1 Like

So i should use it this way ?

LocalisedStrings(String::createStringFromData(BinaryData::ptPT_lng, BinaryData::ptPT_lngSize), false);

 

1 Like

yep

Thank you Jules

Yes I find this really cool ! Thanks U ! I make it like that:

Logger::writeToLog( SystemStats::getUserLanguage());
if(SystemStats::getUserLanguage()=="fr")
{
    juce::LocalisedStrings *currentMappings = new             juce::LocalisedStrings(String::createStringFromData(BinaryData::French_txt, BinaryData::French_txtSize), false);
    juce::LocalisedStrings::setCurrentMappings(currentMappings);


}