GUI: U32: Remove more redundant code, and add UTF-8 check

Modifies the CREATE_TRANSLATIONS tool.

- Remove _charset for PoMessageEntryList
- Add useUTF8 bool variable and helper function
- Add UTF-8 checking for each po file. Error out if file is not coded in UTF-8.
This commit is contained in:
aryanrawlani28 2020-06-28 04:28:59 +05:30 committed by Eugene Sandulenko
parent 3d97be2559
commit 77937f3e2b
3 changed files with 18 additions and 12 deletions

View File

@ -122,6 +122,16 @@ int main(int argc, char *argv[]) {
}
}
for (int i = 0; i < numLangs; i++) {
if (!translations[i]->useUTF8()) {
fprintf(stderr, "ERROR: Po Language file for: \"%s\", named as \"%s\" is not encoded in UTF-8", translations[i]->languageName(), translations[i]->language());
for (size_t j = 0; j < translations.size(); ++j)
delete translations[j];
return -1;
}
}
FILE *outFile;
int i, lang;
int len;

View File

@ -108,14 +108,11 @@ const char *PoMessageList::operator[](int index) const {
}
PoMessageEntryList::PoMessageEntryList(const char *lang) :
_lang(NULL), _charset(NULL), _langName(NULL), _langNameAlt(NULL),
_lang(NULL), _langName(NULL), _langNameAlt(NULL), _useUTF8(true),
_list(NULL), _size(0), _allocated(0)
{
_lang = new char[1 + strlen(lang)];
strcpy(_lang, lang);
// Set default charset to empty string
_charset = new char[1];
_charset[0] = '\0';
// Set default langName to lang
_langNameAlt = new char[1 + strlen(lang)];
strcpy(_langNameAlt, lang);
@ -123,7 +120,6 @@ PoMessageEntryList::PoMessageEntryList(const char *lang) :
PoMessageEntryList::~PoMessageEntryList() {
delete[] _lang;
delete[] _charset;
delete[] _langName;
delete[] _langNameAlt;
for (int i = 0; i < _size; ++i)
@ -146,9 +142,8 @@ void PoMessageEntryList::addMessageEntry(const char *translation, const char *me
_langNameAlt = str;
}
str = parseLine(translation, "charset=");
if (str != NULL) {
delete[] _charset;
_charset = str;
if (str[0] != 'U' || str[1] != 'T' || str[2] != 'F' || str[3] != '-' || str[4] != '8') {
_useUTF8 = false;
}
return;
}
@ -245,8 +240,8 @@ const char *PoMessageEntryList::languageName() const {
return _langName ? _langName : _langNameAlt;
}
const char *PoMessageEntryList::charset() const {
return _charset;
const bool PoMessageEntryList::useUTF8() const {
return _useUTF8;
}
int PoMessageEntryList::size() const {

View File

@ -87,17 +87,18 @@ public:
const char *language() const;
const char *languageName() const;
const char *charset() const;
const bool useUTF8() const;
int size() const;
const PoMessageEntry *entry(int) const;
private:
char *_lang;
char *_charset;
char *_langName;
char *_langNameAlt;
bool _useUTF8;
PoMessageEntry **_list;
int _size;
int _allocated;