Skip to content

Commit

Permalink
Merge pull request #60 from jordimas/iso8859-1
Browse files Browse the repository at this point in the history
Convert string to ISO-8859-1 and remove unneccessary mappings
  • Loading branch information
gfwilliams committed Apr 9, 2024
2 parents e9bda95 + 6c81b26 commit b4224cd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 26 deletions.
2 changes: 1 addition & 1 deletion js/appinfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function translateJS(options, app, code) {
if (translation!==undefined) {
// remap any chars that we don't think we can display in Espruino's
// built in fonts.
translation = Utils.convertStringToISOLatin(translation);
translation = Utils.convertStringToISO8859_1(translation);

Check warning on line 77 in js/appinfo.js

View workflow job for this annotation

GitHub Actions / test

'Utils' is not defined
tokenString = toJSString(translation);

Check warning on line 78 in js/appinfo.js

View workflow job for this annotation

GitHub Actions / test

'toJSString' is not defined
}
} else if (tok.str.startsWith("`")) {
Expand Down
32 changes: 7 additions & 25 deletions js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,84 +70,66 @@ let DEVICEINFO = [
}*/
];

/* When a char is not in Espruino's codepage, try and use
/* When a char is not in Espruino's iso8859-1 codepage, try and use
these conversions */
const CODEPAGE_CONVERSIONS = {
"æ":"e",
"å":"a",
"ą":"a",
"ā":"a",
"à":"a",
"č":"c",
"ć":"c",
"ç":"c",
"ě":"e",
"ę":"e",
"ē":"e",
"è":"e",
"é":"e",
"ģ":"g",
"í":"i",
"ī":"i",
"ï":"i",
"ķ":"k",
"ļ":"l",
"ł":"l",
"ń":"n",
"ņ":"n",
"ő":"o",
"ó":"o",
"ò":"o",
"ø":"o",
"ř":"r",
"ś":"s",
"š":"s",
"ú":"u",
"ū":"u",
"ü":"u",
"ż":"z",
"ź":"z",
"ž":"z",
"Ą":"A",
"Ā":"A",
"À":"A",
"Č":"C",
"Ć":"C",
"Ç":"C",
"Ě":"E",
"Ę":"E",
"Ē":"E",
"È":"E",
"É":"E",
"Ģ":"G",
"Ï":"I",
"Ķ":"K",
"Ļ":"L",
"Ł":"L",
"Ń":"N",
"Ņ":"N",
"Ő":"O",
"Ó":"O",
"Ò":"O",
"Ř":"R",
"Ś":"S",
"Š":"S",
"Ū":"U",
"Ú":"U",
"Ü":"U",
"Ż":"Z",
"Ź":"Z",
"Ž":"Z",
};

/// Convert any character that cannot be displayed by Espruino's built in fonts
/// originally https://github.com/espruino/EspruinoAppLoaderCore/pull/11/files
function convertStringToISOLatin(originalStr) {
function convertStringToISO8859_1(originalStr) {
var chars = originalStr.split('');
for (var i = 0; i < chars.length; i++) {
var ch = chars[i];
if (CODEPAGE_CONVERSIONS[ch])
chars[i] = CODEPAGE_CONVERSIONS[ch];
else if (chars[i].charCodeAt() > 255) {
console.log("Skipped conversion of char: '" + chars[i] + "'");
chars[i] = "?";
}
}
var translatedStr = chars.join('');
if (translatedStr != originalStr)
Expand Down Expand Up @@ -481,7 +463,7 @@ var Utils = {
Const : Const,
DEVICEINFO : DEVICEINFO,
CODEPAGE_CONVERSIONS : CODEPAGE_CONVERSIONS,
convertStringToISOLatin : convertStringToISOLatin,
convertStringToISO8859_1 : convertStringToISO8859_1,
escapeHtml : escapeHtml,
globToRegex : globToRegex,
htmlToArray : htmlToArray,
Expand Down

0 comments on commit b4224cd

Please sign in to comment.