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;
|
int GraphicUserInterface::g_customIdCmdA = 0;
|
||||||
#endif
|
#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 () :
|
GraphicUserInterface::GraphicUserInterface () :
|
||||||
ActiveFrame (nullptr),
|
ActiveFrame (nullptr),
|
||||||
BackgroundMode (false),
|
BackgroundMode (false),
|
||||||
@@ -1349,7 +1362,7 @@ namespace VeraCrypt
|
|||||||
#ifdef TC_RESOURCE_DIR
|
#ifdef TC_RESOURCE_DIR
|
||||||
htmlPath = StringConverter::ToWide (string (TC_TO_STRING (TC_RESOURCE_DIR)) + "/doc/HTML/");
|
htmlPath = StringConverter::ToWide (string (TC_TO_STRING (TC_RESOURCE_DIR)) + "/doc/HTML/");
|
||||||
#elif defined (TC_WINDOWS)
|
#elif defined (TC_WINDOWS)
|
||||||
htmlPath += L"\\docs\\html\\en\\";
|
htmlPath += L"\\docs\\html\\";
|
||||||
#elif defined (TC_MACOSX)
|
#elif defined (TC_MACOSX)
|
||||||
htmlPath += L"/../Resources/doc/HTML/";
|
htmlPath += L"/../Resources/doc/HTML/";
|
||||||
#elif defined (TC_UNIX)
|
#elif defined (TC_UNIX)
|
||||||
@@ -1365,17 +1378,24 @@ namespace VeraCrypt
|
|||||||
if (appDirEnv)
|
if (appDirEnv)
|
||||||
{
|
{
|
||||||
htmlPath = wxString::FromUTF8(appDirEnv);
|
htmlPath = wxString::FromUTF8(appDirEnv);
|
||||||
htmlPath += "/usr/share/doc/veracrypt/HTML/";
|
htmlPath += L"/usr/share/doc/veracrypt/HTML/";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
localFile = false;
|
localFile = false;
|
||||||
#endif
|
#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)
|
if (localFile)
|
||||||
{
|
{
|
||||||
/* check if local file exists */
|
/* check if local file exists */
|
||||||
wxFileName htmlFile = htmlPath + url;
|
wxFileName htmlFile = htmlPath + documentationLang + L"/" + url;
|
||||||
htmlFile.Normalize (
|
htmlFile.Normalize (
|
||||||
wxPATH_NORM_ENV_VARS |
|
wxPATH_NORM_ENV_VARS |
|
||||||
wxPATH_NORM_DOTS |
|
wxPATH_NORM_DOTS |
|
||||||
@@ -1385,11 +1405,32 @@ namespace VeraCrypt
|
|||||||
wxPATH_NORM_TILDE
|
wxPATH_NORM_TILDE
|
||||||
);
|
);
|
||||||
localFile = htmlFile.FileExists();
|
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)
|
if (!localFile)
|
||||||
{
|
{
|
||||||
htmlPath = L"https://veracrypt.jp/en/";
|
htmlPath = L"https://veracrypt.jp/" + documentationLang + L"/";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ namespace VeraCrypt
|
|||||||
Map[StringConverter::ToSingle (wstring (node.Attributes[L"key"]))] = text;
|
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"))
|
foreach (XmlNode node, XmlParser (translatedXml).GetNodes (L"entry"))
|
||||||
{
|
{
|
||||||
wxString text = node.InnerText;
|
wxString text = node.InnerText;
|
||||||
|
|||||||
@@ -28,10 +28,12 @@ namespace VeraCrypt
|
|||||||
|
|
||||||
bool Exists (const string &key) const { return Map.find (key) != Map.end(); }
|
bool Exists (const string &key) const { return Map.find (key) != Map.end(); }
|
||||||
wstring Get (const string &key) const;
|
wstring Get (const string &key) const;
|
||||||
|
string GetPreferredLang () const { return PreferredLang; }
|
||||||
void Init ();
|
void Init ();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
map <string, wstring> Map;
|
map <string, wstring> Map;
|
||||||
|
string PreferredLang;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
LanguageStrings (const LanguageStrings &);
|
LanguageStrings (const LanguageStrings &);
|
||||||
|
|||||||
@@ -47,13 +47,14 @@ namespace VeraCrypt
|
|||||||
}
|
}
|
||||||
#endif // TC_WINDOWS
|
#endif // TC_WINDOWS
|
||||||
|
|
||||||
string Resources::GetLanguageXml ()
|
string Resources::GetLanguageXml (string& xmlLang)
|
||||||
{
|
{
|
||||||
#ifdef TC_WINDOWS
|
#ifdef TC_WINDOWS
|
||||||
ConstBufferPtr res = GetWindowsResource (L"XML", L"IDR_LANGUAGE");
|
ConstBufferPtr res = GetWindowsResource (L"XML", L"IDR_LANGUAGE");
|
||||||
Buffer strBuf (res.Size() + 1);
|
Buffer strBuf (res.Size() + 1);
|
||||||
strBuf.Zero();
|
strBuf.Zero();
|
||||||
strBuf.CopyFrom (res);
|
strBuf.CopyFrom (res);
|
||||||
|
xmlLang = "en";
|
||||||
return string (reinterpret_cast <char *> (strBuf.Ptr()));
|
return string (reinterpret_cast <char *> (strBuf.Ptr()));
|
||||||
#else
|
#else
|
||||||
// get language from env LANG
|
// get language from env LANG
|
||||||
@@ -68,7 +69,7 @@ namespace VeraCrypt
|
|||||||
#endif
|
#endif
|
||||||
string filenamePost(".xml");
|
string filenamePost(".xml");
|
||||||
string filename = filenamePrefix + defaultLang + filenamePost;
|
string filename = filenamePrefix + defaultLang + filenamePost;
|
||||||
|
xmlLang = defaultLang;
|
||||||
UserPreferences Preferences;
|
UserPreferences Preferences;
|
||||||
Preferences.Load();
|
Preferences.Load();
|
||||||
string preferredLang = string(Preferences.Language.begin(), Preferences.Language.end());
|
string preferredLang = string(Preferences.Language.begin(), Preferences.Language.end());
|
||||||
@@ -91,34 +92,42 @@ namespace VeraCrypt
|
|||||||
if (foundUnderscore > 0) {
|
if (foundUnderscore > 0) {
|
||||||
lowerLangTag.replace(foundUnderscore, 1, 1, '-');
|
lowerLangTag.replace(foundUnderscore, 1, 1, '-');
|
||||||
filename = filenamePrefix + lowerLangTag + filenamePost;
|
filename = filenamePrefix + lowerLangTag + filenamePost;
|
||||||
|
xmlLang = lowerLangTag;
|
||||||
FilesystemPath xml(filename);
|
FilesystemPath xml(filename);
|
||||||
if (!xml.IsFile()) {
|
if (!xml.IsFile()) {
|
||||||
string shortLangTag = lowerLangTag.substr(0, foundUnderscore);
|
string shortLangTag = lowerLangTag.substr(0, foundUnderscore);
|
||||||
filename = filenamePrefix + shortLangTag + filenamePost;
|
filename = filenamePrefix + shortLangTag + filenamePost;
|
||||||
|
xmlLang = shortLangTag;
|
||||||
FilesystemPath xml(filename);
|
FilesystemPath xml(filename);
|
||||||
if (!xml.IsFile()) {
|
if (!xml.IsFile()) {
|
||||||
filename = filenamePrefix + defaultLang + filenamePost;
|
filename = filenamePrefix + defaultLang + filenamePost;
|
||||||
|
xmlLang = defaultLang;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
filename = filenamePrefix + langTag + filenamePost;
|
filename = filenamePrefix + langTag + filenamePost;
|
||||||
|
xmlLang = langTag;
|
||||||
FilesystemPath xml(filename);
|
FilesystemPath xml(filename);
|
||||||
if (!xml.IsFile()) {
|
if (!xml.IsFile()) {
|
||||||
filename = filenamePrefix + defaultLang + filenamePost;
|
filename = filenamePrefix + defaultLang + filenamePost;
|
||||||
|
xmlLang = defaultLang;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
string lowerLang(StringConverter::ToLower(lang));
|
string lowerLang(StringConverter::ToLower(lang));
|
||||||
filename = filenamePrefix + lowerLang + filenamePost;
|
filename = filenamePrefix + lowerLang + filenamePost;
|
||||||
|
xmlLang = lowerLang;
|
||||||
FilesystemPath xml(filename);
|
FilesystemPath xml(filename);
|
||||||
if (!xml.IsFile()) {
|
if (!xml.IsFile()) {
|
||||||
int foundUnderscore = lowerLang.find("_");
|
int foundUnderscore = lowerLang.find("_");
|
||||||
if (foundUnderscore > 0) {
|
if (foundUnderscore > 0) {
|
||||||
lowerLang.replace(foundUnderscore, 1, 1, '-');
|
lowerLang.replace(foundUnderscore, 1, 1, '-');
|
||||||
filename = filenamePrefix + lowerLang + filenamePost;
|
filename = filenamePrefix + lowerLang + filenamePost;
|
||||||
|
xmlLang = lowerLang;
|
||||||
FilesystemPath xml(filename);
|
FilesystemPath xml(filename);
|
||||||
if (!xml.IsFile()) {
|
if (!xml.IsFile()) {
|
||||||
filename = filenamePrefix + defaultLang + filenamePost;
|
filename = filenamePrefix + defaultLang + filenamePost;
|
||||||
|
xmlLang = defaultLang;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -127,6 +136,7 @@ namespace VeraCrypt
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
filename = filenamePrefix + preferredLang + filenamePost;
|
filename = filenamePrefix + preferredLang + filenamePost;
|
||||||
|
xmlLang = preferredLang;
|
||||||
}
|
}
|
||||||
FilesystemPath xml(filename);
|
FilesystemPath xml(filename);
|
||||||
if ( xml.IsFile() ){
|
if ( xml.IsFile() ){
|
||||||
@@ -145,6 +155,7 @@ namespace VeraCrypt
|
|||||||
, 0
|
, 0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
xmlLang = defaultLang; // fallback to default language
|
||||||
return string ((const char*) LanguageXml);
|
return string ((const char*) LanguageXml);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ namespace VeraCrypt
|
|||||||
class Resources
|
class Resources
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static string GetLanguageXml ();
|
static string GetLanguageXml (string& preferredLang);
|
||||||
static string GetLegalNotices ();
|
static string GetLegalNotices ();
|
||||||
#ifndef TC_NO_GUI
|
#ifndef TC_NO_GUI
|
||||||
static wxBitmap GetDriveIconBitmap ();
|
static wxBitmap GetDriveIconBitmap ();
|
||||||
|
|||||||
Reference in New Issue
Block a user