5.5 KiB
How-to add a new language to Prusa Firmware
We will use Dutch as an example here.
Prepare Prusa Firmware
QR = placeholder for language in upper case
qr = placehodler for language in lower case
AB = placeholder for hexadecial
Files needs to be modified
-
../Firmware/language.hIn section
/** @name Language codes (ISO639-1)*/add the new#define LANG_CODE_QR 0xABAB //!<'qr'following ISO639-1 convention for QR. https://en.wikipedia.org/wiki/List_of_ISO_639-1_codesExample:
#define LANG_CODE_NL 0x6e6c //!<'nl'where the hex value0x6e6cis in asciinl -
../Firmware/language.cIn section
const char* lang_get_name_by_code(uint16_t code)addcase LANG_CODE_NL: return _n("Language");Example:
case LANG_CODE_NL: return _n("Nederlands");WhereLanguageis native spoken version, hereNederlands(Netherlands) orVlaams(Belgium). This will be displayed on the LCD menu. -
../lang/lang-add.shIn section
cat lang_add.txt | sed 's/^/"/;s/$/"/' | while read new_s; doaddinsert_qr "$new_s" 'qr'where qrExample:
insert_qr "$new_s" 'nl'with qr valuenlfor Dutch -
../lang/lang-build.shIn section
#returns hexadecial data for lang codeadd a case*qr*) echo '0x71\0x72'Example:
*nl*) echo '\x6c\x6e' ;;!!! IMPORTANT that the hex values are switched so 'nl' is here in 'ln' !!!In generate "all" section add `generate_binary 'qr'
Example:
generate_binary 'nl' -
../lang/lang-check.pyAdd in
helpthe new languageqrExample: From
help="Check lang file (en|cs|de|es|fr|it|pl)")tohelp="Check lang file (en|cs|de|es|fr|nl|it|pl)") -
In
../lang/lang-clean.shIn section echo
"lang-clean.sh started" >&2addclean_lang qrExample:
clean_lang nl -
../lang/lang-export.shIn section
# if 'all' is selected, script will generate all po files and also pot fileadd./lang-export.sh qrExample:
./lang-export.sh nlIn section
# language name in englishadd*qr*) echo "Language-in-English" ;;Example:
*nl*) echo "Dutch" ;; -
../lang/lang-import.shIn section
#replace in languages translationadd new rule set for the language. As the LCD screen doesn't not support äöüßéè and other special characters, it makes sense to "normalize" these.Example:
#replace in dutch translation according to https://nl.wikipedia.org/wiki/Accenttekens_in_de_Nederlandse_spelling if [ "$LNG" = "nl" ]; then #replace 'ë' with 'e' sed -i 's/\xc3\xab/e/g' $LNG'_filtered.po' #replace 'ï' with 'i' sed -i 's/\xc3\xaf/i/g' $LNG'_filtered.po' #replace 'é' with 'e' sed -i 's/\xc3\xa9/e/g' $LNG'_filtered.po' #replace 'è' with 'e' (left) sed -i 's/\xc3\xa8/e/g' $LNG'_filtered.po' #replace 'ö' with 'o' (left) sed -i 's/\xc3\xb6/o/g' $LNG'_filtered.po' #replace 'ê' with 'e' (left) sed -i 's/\xc3\xaa/e/g' $LNG'_filtered.po' #replace 'ü' with 'u' (left) sed -i 's/\xc3\xbc/u/g' $LNG'_filtered.po' #replace 'ç' with 'c' (left) sed -i 's/\xc3\xa7/c/g' $LNG'_filtered.po' #replace 'á' with 'a' (left) sed -i 's/\xc3\xa1/a/g' $LNG'_filtered.po' #replace 'à' with 'a' (left) sed -i 's/\xc3\xa0/a/g' $LNG'_filtered.po' #replace 'ä' with 'a' (left) sed -i 's/\xc3\xa4/a/g' $LNG'_filtered.po' #replace 'û' with 'u' (left) sed -i 's/\xc3\xbc/u/g' $LNG'_filtered.po' #replace 'î' with 'i' (left) sed -i 's/\xc3\xae/i/g' $LNG'_filtered.po' #replace 'í' with 'i' (left) sed -i 's/\xc3\xad/i/g' $LNG'_filtered.po' #replace 'ô' with 'o' (left) sed -i 's/\xc3\xb4/o/g' $LNG'_filtered.po' #replace 'ú' with 'u' (left) sed -i 's/\xc3\xba/u/g' $LNG'_filtered.po' #replace 'ñ' with 'n' (left) sed -i 's/\xc3\xb1/n/g' $LNG'_filtered.po' #replace 'â' with 'a' (left) sed -i 's/\xc3\xa2/a/g' $LNG'_filtered.po' #replace 'Å' with 'A' (left) sed -i 's/\xc3\x85/A/g' $LNG'_filtered.po' fi -
../lang/fw-build.shIn section
#update _SEC_LANG in binary file if language is selectedaddif [ -e lang_qr.bin ]; then echo -n " Language-in-English : " >&2 ./update_lang.sh qr 2>./update_lang_qr.out 1>/dev/null if [ $? -eq 0 ]; then echo 'OK' >&2; else echo 'NG!' >&2; fi fiExample:
if [ -e lang_nl.bin ]; then echo -n " Dutch : " >&2 ./update_lang.sh nl 2>./update_lang_nl.out 1>/dev/null if [ $? -eq 0 ]; then echo 'OK' >&2; else echo 'NG!' >&2; fi fiIn section
#create binary file with all languagesaddif [ -e lang_qr.bin ]; then cat lang_qr.bin >> lang.bin; fiExample:
if [ -e lang_nl.bin ]; then cat lang_nl.bin >> lang.bin; fi -
../lang/fw-clean.shIn section
echo "fw-clean.sh started" >&2addrm_if_exists firmware_qr.hex ... ... rm_if_exists update_lang_qr.outExample:
rm_if_exists firmware_nl.hexand
rm_if_exists update_lang_nl.out
Prepare language part
To prepare the actual language translation files we need create the lang_en_qr.txt file.
- Copy and
lang_en.txtaslang_en_qr.txt - run
../lang/lang-export.sh - copy
../lang/po/Firmware_qr.pofile to../lang/po/new/qr.po - translate all messages using POEdit or other tools.
- use
lang/lang-import.sh qrto generatelang_en_qr.txtfrom translated po files - move
../lang/po/new/lang_en_qr.txtto../lang/lang_en_qr.txt - cleanup
../lang/po/newfolder by deletingqr_filtered.po qr_new.po noasci.txt