Skip to content

Commit

Permalink
- Rewrite the script written in VBScript in JScript
Browse files Browse the repository at this point in the history
- Remove support for po file encoding other than UTF-8.
  • Loading branch information
sdottaka committed Feb 14, 2024
1 parent cdc0455 commit b846962
Show file tree
Hide file tree
Showing 17 changed files with 583 additions and 728 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Translations/**/*.po text eol=lf
21 changes: 6 additions & 15 deletions FRHED/LangArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ void LangArray::StringData::Unshare(char *data)

LangArray::LangArray()
: m_hLangDll(0)
, m_codepage(0)
, m_langid(0)
{
}
Expand All @@ -99,10 +98,9 @@ void LangArray::ClearAll()

/**
* @brief Convert C style \\nnn, \\r, \\n, \\t etc into their indicated characters.
* @param [in] codepage Codepage to use in conversion.
* @param [in,out] s String to convert.
*/
static size_t unslash(unsigned codepage, char *s)
static size_t unslash(char *s)
{
char *p = s;
char *q = p;
Expand Down Expand Up @@ -148,7 +146,7 @@ static size_t unslash(unsigned codepage, char *s)
// fall through
default:
*p = c;
if ((c & 0x80) && IsDBCSLeadByteEx(codepage, c))
if ((c & 0x80) && IsDBCSLeadByteEx(CP_UTF8, c))
*++p = *r++;
q = r;
}
Expand Down Expand Up @@ -303,8 +301,6 @@ BOOL LangArray::Load(HINSTANCE hMainInstance, LANGID langid, LPCTSTR langdir)
if (char *q = strchr(p, ':'))
{
int line = strtol(q + 1, &q, 10);
if (line == 367)
line = line;
lines.add(line);
--unresolved;
}
Expand Down Expand Up @@ -341,7 +337,7 @@ BOOL LangArray::Load(HINSTANCE hMainInstance, LANGID langid, LPCTSTR langdir)
ps = 0;
if (msgstr.length() == 0)
msgstr.append(msgid.c_str(), msgid.length());
msgstr.resize(unslash(m_codepage, msgstr.pointer()));
msgstr.resize(unslash(msgstr.pointer()));
if (int i = lines.size())
{
StringData *psd = StringData::Create(msgstr.c_str(), msgstr.length());
Expand All @@ -366,11 +362,6 @@ BOOL LangArray::Load(HINSTANCE hMainInstance, LANGID langid, LPCTSTR langdir)
} while (i);
}
lines.clear();
if (strcmp(directive.c_str(), "Codepage") == 0)
{
m_codepage = strtol(msgstr.c_str(), &p, 10);
directive.clear();
}
msgid.clear();
msgstr.clear();
}
Expand Down Expand Up @@ -399,7 +390,7 @@ PTSTR LangArray::TranslateString(int line)
if (UINT len = static_cast<UINT>(strlen(s)))
{
ws = SysAllocStringLen(0, len);
len = MultiByteToWideChar(m_codepage, 0, s, -1, ws, len + 1);
len = MultiByteToWideChar(CP_UTF8, 0, s, -1, ws, len + 1);
SysReAllocStringLen(&ws, ws, len - 1);
}
}
Expand All @@ -414,11 +405,11 @@ PTSTR LangArray::TranslateString(int line)
if (UINT len = static_cast<UINT>(strlen(s)))
{
unsigned codepage = GetACP();
if (m_codepage != codepage)
if (CP_UTF8 != codepage)
{
// Attempt to convert to UI codepage
BSTR ws = SysAllocStringLen(0, len);
len = MultiByteToWideChar(m_codepage, 0, s, -1, ws, len + 1);
len = MultiByteToWideChar(CP_UTF8, 0, s, -1, ws, len + 1);
if (len)
{
SysReAllocStringLen(&ws, ws, len - 1);
Expand Down
1 change: 0 additions & 1 deletion FRHED/LangArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class LangArray : protected Vector<char *>
static void Unshare(char *);
};
HMODULE m_hLangDll;
unsigned m_codepage;
LANGID m_langid;
LangArray();
~LangArray();
Expand Down
4 changes: 2 additions & 2 deletions FRHED/PreLink.bat
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ echo $(IntDir) = %1
echo $(TargetPath) = %2
echo $(PlatformTarget) = %3
cd ..\Translations\Frhed
cscript CreateMasterPotFile.vbs
cscript UpdatePoFilesFromPotFile.vbs
cscript CreateMasterPotFile.js
cscript UpdatePoFilesFromPotFile.js
cd ..\..\FRHED
rc "/fo%~1\lang.res" /i.. ..\Translations\Frhed\heksedit.rc
mkdir "%~2\..\Languages"
Expand Down
Loading

0 comments on commit b846962

Please sign in to comment.