2019-09-14 13:50:25 +00:00
# How-to add a new language to Prusa Firmware
We will use Dutch as an example here.
## Prepare Prusa Firmware
2022-02-10 18:01:04 +00:00
QR = placeholder for language in upper case
2019-09-14 13:52:59 +00:00
2022-02-14 07:39:03 +00:00
qr = placeholder for language in lower case
2019-09-14 13:52:59 +00:00
2022-02-14 07:39:03 +00:00
AB = placeholder for hexadecimal
2019-09-14 13:50:25 +00:00
Files needs to be modified
2019-09-14 13:54:37 +00:00
- `../Firmware/language.h`
2019-09-14 13:50:25 +00:00
2021-03-01 07:33:32 +00:00
In section `/** @name Language codes (ISO639-1)*/` add the new `#define LANG_CODE_QR 0xABAB //!<'qr'` following ISO639-1 convention for QR.
2019-09-14 13:50:25 +00:00
https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
Example:
`#define LANG_CODE_NL 0x6e6c //!<'nl'` where the hex value `0x6e6c` is in ascii `nl`
2019-09-14 13:54:37 +00:00
- `../Firmware/language.c`
2019-09-14 13:50:25 +00:00
In section `const char* lang_get_name_by_code(uint16_t code)` add `case LANG_CODE_NL: return _n("Language");`
Example:
`case LANG_CODE_NL: return _n("Nederlands");` Where `Language` is native spoken version, here `Nederlands` (Netherlands) or `Vlaams` (Belgium). This will be displayed on the LCD menu.
2019-09-14 13:54:37 +00:00
- `../lang/lang-add.sh`
2019-09-14 13:50:25 +00:00
2021-03-01 07:33:32 +00:00
In section `cat lang_add.txt | sed 's/^/"/;s/$/"/' | while read new_s; do` add `insert_qr "$new_s" 'qr'` where qr
2019-09-14 13:50:25 +00:00
Example:
2021-03-01 07:33:32 +00:00
`insert_qr "$new_s" 'nl'` with qr value `nl` for Dutch
2019-09-14 13:50:25 +00:00
2019-09-14 13:54:37 +00:00
- `../lang/lang-build.sh`
2019-09-14 13:50:25 +00:00
2022-02-14 07:39:03 +00:00
In section `#returns hexadecimal data for lang code` add a case `*qr*) echo '0x71\0x72'`
2019-09-14 13:50:25 +00:00
Example:
`*nl*) echo '\x6c\x6e' ;;` !!! IMPORTANT that the hex values are switched so 'nl' is here in 'ln' !!!
2021-03-01 07:33:32 +00:00
In generate "all" section add `generate_binary 'qr'
2019-09-14 13:50:25 +00:00
Example:
`generate_binary 'nl'`
2019-09-14 13:54:37 +00:00
- `../lang/lang-check.py`
2019-09-14 13:50:25 +00:00
2021-03-01 07:33:32 +00:00
Add in `help` the new language `qr`
2019-09-14 13:50:25 +00:00
Example:
From `help="Check lang file (en|cs|de|es|fr|it|pl)")` to `help="Check lang file (en|cs|de|es|fr|nl|it|pl)")`
- In `../lang/lang-clean.sh`
2021-03-01 07:33:32 +00:00
In section echo `"lang-clean.sh started" >&2` add `clean_lang qr`
2019-09-14 13:50:25 +00:00
Example:
`clean_lang nl`
2019-09-14 13:54:37 +00:00
- `../lang/lang-export.sh`
2019-09-14 13:50:25 +00:00
2021-03-01 07:33:32 +00:00
In section `# if 'all' is selected, script will generate all po files and also pot file` add `./lang-export.sh qr`
2019-09-14 13:50:25 +00:00
Example:
`./lang-export.sh nl`
2021-03-01 07:33:32 +00:00
In section ` # language name in english` add `*qr*) echo "Language-in-English" ;;`
2019-09-14 13:50:25 +00:00
Example:
`*nl*) echo "Dutch" ;;`
2019-09-14 13:54:37 +00:00
- `../lang/lang-import.sh`
2019-09-14 13:50:25 +00:00
In section `#replace in languages translation` add 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
2019-09-14 13:52:59 +00:00
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
```
2019-09-14 13:50:25 +00:00
2019-09-14 13:54:37 +00:00
- `../lang/fw-build.sh`
2019-09-14 13:50:25 +00:00
In section `#update _SEC_LANG in binary file if language is selected` add
```
2021-03-01 07:33:32 +00:00
if [ -e lang_qr.bin ]; then
2019-09-14 13:50:25 +00:00
echo -n " Language-in-English : " >& 2
2021-03-01 07:33:32 +00:00
./update_lang.sh qr 2>./update_lang_qr.out 1>/dev/null
2019-09-14 13:50:25 +00:00
if [ $? -eq 0 ]; then echo 'OK' >&2; else echo 'NG!' >&2; fi
fi
2019-09-14 13:59:44 +00:00
```
2019-09-14 13:50:25 +00:00
Example:
```
2019-09-14 13:57:08 +00:00
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
fi
2019-09-14 13:50:25 +00:00
```
2021-03-01 07:33:32 +00:00
In section `#create binary file with all languages` add `if [ -e lang_qr.bin ]; then cat lang_qr.bin >> lang.bin; fi`
2019-09-14 13:50:25 +00:00
Example:
2019-09-14 13:59:44 +00:00
2019-09-14 13:50:25 +00:00
`if [ -e lang_nl.bin ]; then cat lang_nl.bin >> lang.bin; fi`
2019-09-14 13:54:37 +00:00
- `../lang/fw-clean.sh`
2019-09-14 13:50:25 +00:00
2019-09-14 13:57:51 +00:00
In section `echo "fw-clean.sh started" >&2` add
2019-09-14 13:50:25 +00:00
```
2021-03-01 07:33:32 +00:00
rm_if_exists firmware_qr.hex
2019-09-14 13:50:25 +00:00
...
...
2021-03-01 07:33:32 +00:00
rm_if_exists update_lang_qr.out
2019-09-14 13:50:25 +00:00
```
Example:
`rm_if_exists firmware_nl.hex`
2019-09-14 13:57:08 +00:00
2019-09-14 13:50:25 +00:00
and
2019-09-14 13:57:08 +00:00
2019-09-14 13:50:25 +00:00
`rm_if_exists update_lang_nl.out`
## Prepare language part
2022-02-10 18:01:04 +00:00
To prepare the actual language translation files we need create the `lang_en_qr.txt` file.
2021-03-01 07:33:32 +00:00
1. Copy and `lang_en.txt` as `lang_en_qr.txt`
2019-09-14 14:26:57 +00:00
2. run `../lang/lang-export.sh`
2021-03-01 07:33:32 +00:00
3. copy `../lang/po/Firmware_qr.po` file to `../lang/po/new/qr.po`
2019-09-14 14:26:57 +00:00
4. translate all messages using POEdit or other tools.
2021-03-01 07:33:32 +00:00
5. use `lang/lang-import.sh qr` to generate `lang_en_qr.txt` from translated po files
6. move `../lang/po/new/lang_en_qr.txt` to `../lang/lang_en_qr.txt`
2019-09-14 14:26:57 +00:00
7. cleanup `../lang/po/new` folder by deleting
```
2021-03-01 07:33:32 +00:00
qr_filtered.po
qr_new.po
2022-02-14 07:39:03 +00:00
nonascii.txt
2019-09-14 14:26:57 +00:00
```
2022-02-10 18:01:04 +00:00
##