mirror of
https://github.com/veracrypt/VeraCrypt.git
synced 2025-11-11 02:58:02 -06:00
Linux: Update local documentation logic to the new organization of folders under "docs/html"
This commit is contained in:
@@ -68,6 +68,19 @@ namespace VeraCrypt
|
||||
int GraphicUserInterface::g_customIdCmdA = 0;
|
||||
#endif
|
||||
|
||||
// Check if given language has a corresponding translated documentation
|
||||
static BOOL HasTranslatedDocumentation(const char* language)
|
||||
{
|
||||
// hardcoded list of languages for which a translated documentation exists
|
||||
const char* supportedLanguages[] = { "en", "ru", "zh-cn"};
|
||||
for (int i = 0; i < sizeof(supportedLanguages) / sizeof(supportedLanguages[0]); i++)
|
||||
{
|
||||
if (strcmp(language, supportedLanguages[i]) == 0)
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
GraphicUserInterface::GraphicUserInterface () :
|
||||
ActiveFrame (nullptr),
|
||||
BackgroundMode (false),
|
||||
@@ -1349,7 +1362,7 @@ namespace VeraCrypt
|
||||
#ifdef TC_RESOURCE_DIR
|
||||
htmlPath = StringConverter::ToWide (string (TC_TO_STRING (TC_RESOURCE_DIR)) + "/doc/HTML/");
|
||||
#elif defined (TC_WINDOWS)
|
||||
htmlPath += L"\\docs\\html\\en\\";
|
||||
htmlPath += L"\\docs\\html\\";
|
||||
#elif defined (TC_MACOSX)
|
||||
htmlPath += L"/../Resources/doc/HTML/";
|
||||
#elif defined (TC_UNIX)
|
||||
@@ -1365,17 +1378,24 @@ namespace VeraCrypt
|
||||
if (appDirEnv)
|
||||
{
|
||||
htmlPath = wxString::FromUTF8(appDirEnv);
|
||||
htmlPath += "/usr/share/doc/veracrypt/HTML/";
|
||||
htmlPath += L"/usr/share/doc/veracrypt/HTML/";
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
localFile = false;
|
||||
#endif
|
||||
string preferredLang = LangString.GetPreferredLang();
|
||||
// Use preferred language only if it has translated documentation
|
||||
if (!HasTranslatedDocumentation (preferredLang))
|
||||
{
|
||||
preferredLang = "en";
|
||||
}
|
||||
wstring documentationLang = StringConverter::ToWide (preferredLang);
|
||||
if (localFile)
|
||||
{
|
||||
/* check if local file exists */
|
||||
wxFileName htmlFile = htmlPath + url;
|
||||
wxFileName htmlFile = htmlPath + documentationLang + L"/" + url;
|
||||
htmlFile.Normalize (
|
||||
wxPATH_NORM_ENV_VARS |
|
||||
wxPATH_NORM_DOTS |
|
||||
@@ -1385,11 +1405,32 @@ namespace VeraCrypt
|
||||
wxPATH_NORM_TILDE
|
||||
);
|
||||
localFile = htmlFile.FileExists();
|
||||
if (!localFile)
|
||||
{
|
||||
htmlFile = htmlPath + L"en/" + url;
|
||||
htmlFile.Normalize (
|
||||
wxPATH_NORM_ENV_VARS |
|
||||
wxPATH_NORM_DOTS |
|
||||
wxPATH_NORM_CASE |
|
||||
wxPATH_NORM_LONG |
|
||||
wxPATH_NORM_SHORTCUT |
|
||||
wxPATH_NORM_TILDE
|
||||
);
|
||||
localFile = htmlFile.FileExists();
|
||||
if (localFile)
|
||||
{
|
||||
htmlPath += L"en/";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
htmlPath += documentationLang + L"/";
|
||||
}
|
||||
}
|
||||
|
||||
if (!localFile)
|
||||
{
|
||||
htmlPath = L"https://veracrypt.jp/en/";
|
||||
htmlPath = L"https://veracrypt.jp/" + documentationLang + L"/";
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace VeraCrypt
|
||||
Map[StringConverter::ToSingle (wstring (node.Attributes[L"key"]))] = text;
|
||||
}
|
||||
|
||||
string translatedXml = Resources::GetLanguageXml();
|
||||
string translatedXml = Resources::GetLanguageXml(PreferredLang);
|
||||
foreach (XmlNode node, XmlParser (translatedXml).GetNodes (L"entry"))
|
||||
{
|
||||
wxString text = node.InnerText;
|
||||
|
||||
@@ -28,10 +28,12 @@ namespace VeraCrypt
|
||||
|
||||
bool Exists (const string &key) const { return Map.find (key) != Map.end(); }
|
||||
wstring Get (const string &key) const;
|
||||
string GetPreferredLang () const { return PreferredLang; }
|
||||
void Init ();
|
||||
|
||||
protected:
|
||||
map <string, wstring> Map;
|
||||
string PreferredLang;
|
||||
|
||||
private:
|
||||
LanguageStrings (const LanguageStrings &);
|
||||
|
||||
@@ -47,13 +47,14 @@ namespace VeraCrypt
|
||||
}
|
||||
#endif // TC_WINDOWS
|
||||
|
||||
string Resources::GetLanguageXml ()
|
||||
string Resources::GetLanguageXml (string& xmlLang)
|
||||
{
|
||||
#ifdef TC_WINDOWS
|
||||
ConstBufferPtr res = GetWindowsResource (L"XML", L"IDR_LANGUAGE");
|
||||
Buffer strBuf (res.Size() + 1);
|
||||
strBuf.Zero();
|
||||
strBuf.CopyFrom (res);
|
||||
xmlLang = "en";
|
||||
return string (reinterpret_cast <char *> (strBuf.Ptr()));
|
||||
#else
|
||||
// get language from env LANG
|
||||
@@ -68,7 +69,7 @@ namespace VeraCrypt
|
||||
#endif
|
||||
string filenamePost(".xml");
|
||||
string filename = filenamePrefix + defaultLang + filenamePost;
|
||||
|
||||
xmlLang = defaultLang;
|
||||
UserPreferences Preferences;
|
||||
Preferences.Load();
|
||||
string preferredLang = string(Preferences.Language.begin(), Preferences.Language.end());
|
||||
@@ -91,34 +92,42 @@ namespace VeraCrypt
|
||||
if (foundUnderscore > 0) {
|
||||
lowerLangTag.replace(foundUnderscore, 1, 1, '-');
|
||||
filename = filenamePrefix + lowerLangTag + filenamePost;
|
||||
xmlLang = lowerLangTag;
|
||||
FilesystemPath xml(filename);
|
||||
if (!xml.IsFile()) {
|
||||
string shortLangTag = lowerLangTag.substr(0, foundUnderscore);
|
||||
filename = filenamePrefix + shortLangTag + filenamePost;
|
||||
xmlLang = shortLangTag;
|
||||
FilesystemPath xml(filename);
|
||||
if (!xml.IsFile()) {
|
||||
filename = filenamePrefix + defaultLang + filenamePost;
|
||||
xmlLang = defaultLang;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
filename = filenamePrefix + langTag + filenamePost;
|
||||
xmlLang = langTag;
|
||||
FilesystemPath xml(filename);
|
||||
if (!xml.IsFile()) {
|
||||
filename = filenamePrefix + defaultLang + filenamePost;
|
||||
xmlLang = defaultLang;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
string lowerLang(StringConverter::ToLower(lang));
|
||||
filename = filenamePrefix + lowerLang + filenamePost;
|
||||
xmlLang = lowerLang;
|
||||
FilesystemPath xml(filename);
|
||||
if (!xml.IsFile()) {
|
||||
int foundUnderscore = lowerLang.find("_");
|
||||
if (foundUnderscore > 0) {
|
||||
lowerLang.replace(foundUnderscore, 1, 1, '-');
|
||||
filename = filenamePrefix + lowerLang + filenamePost;
|
||||
xmlLang = lowerLang;
|
||||
FilesystemPath xml(filename);
|
||||
if (!xml.IsFile()) {
|
||||
filename = filenamePrefix + defaultLang + filenamePost;
|
||||
xmlLang = defaultLang;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -127,6 +136,7 @@ namespace VeraCrypt
|
||||
}
|
||||
} else {
|
||||
filename = filenamePrefix + preferredLang + filenamePost;
|
||||
xmlLang = preferredLang;
|
||||
}
|
||||
FilesystemPath xml(filename);
|
||||
if ( xml.IsFile() ){
|
||||
@@ -145,6 +155,7 @@ namespace VeraCrypt
|
||||
, 0
|
||||
};
|
||||
|
||||
xmlLang = defaultLang; // fallback to default language
|
||||
return string ((const char*) LanguageXml);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace VeraCrypt
|
||||
class Resources
|
||||
{
|
||||
public:
|
||||
static string GetLanguageXml ();
|
||||
static string GetLanguageXml (string& preferredLang);
|
||||
static string GetLegalNotices ();
|
||||
#ifndef TC_NO_GUI
|
||||
static wxBitmap GetDriveIconBitmap ();
|
||||
|
||||
Reference in New Issue
Block a user