2020-12-31 01:39:32 +00:00
# RaSCSI Web
2021-05-23 15:55:24 +00:00
## Setup local dev env
2020-12-31 01:39:32 +00:00
2021-05-23 15:55:24 +00:00
```bash
2022-02-02 04:51:51 +00:00
# Change to python/web/src
$ cd python/web
2021-05-23 15:55:24 +00:00
# Make a virtual env named venv
$ python3 -m venv venv
# Use that virtual env in this shell
$ source venv/bin/activate
# Install requirements
$ pip install -r requirements.txt
# Use mocks and a temp dir - start the web server
2022-02-02 04:51:51 +00:00
$ BASE_DIR=/tmp/images/ PATH=$PATH:`pwd`/mock/bin/ cd python/web & & PYTHON_COMMON_PATH=$(dirname $PWD)/common/src PYTHONPATH=$PWD/src:${PYTHON_COMMON_PATH} python3 src/web.py
2021-05-23 15:55:24 +00:00
```
### Mocks for local development
2021-10-06 01:39:26 +00:00
You may edit the files under `mock/bin` to simulate Linux command responses.
TODO: rascsi-web uses protobuf commands to send and receive data from rascsi.
2021-11-07 00:25:02 +00:00
A separate mocking solution will be needed for this interface.
2022-08-28 01:38:23 +00:00
## (Optional) Pushing to the Pi via git
This is a setup for pushing code changes from your local development environment to the Raspberry Pi without a roundtrip to the remote GitHub repository.
2021-05-23 15:55:24 +00:00
Setup a bare repo on the rascsi
2020-12-31 01:39:32 +00:00
```
2021-05-23 15:55:24 +00:00
$ ssh pi@rascsi
$ mkdir /home/pi/dev.git & & cd /home/pi/dev.git
$ git --bare init
Initialized empty Git repository in /home/pi/dev.git
2020-12-31 01:39:32 +00:00
```
2021-05-23 15:55:24 +00:00
Locally
```
$ cd ~/source/RASCSI
$ git remote add pi ssh://pi@rascsi/home/pi/dev.git
$ git push pi master
```
2021-12-26 21:36:12 +00:00
## Localizing the Web Interface
2022-08-26 00:57:44 +00:00
We use the Flask-Babel library and Flask/Jinja2 extension for internationalization (i18n).
2021-12-26 21:36:12 +00:00
2022-05-02 19:42:09 +00:00
It uses the 'pybabel' command line tool for extracting and compiling localizations. The Web Interface start script will automatically compile localizations upon launch.
2021-12-27 06:00:29 +00:00
Activate the Python venv in src/web/ to use it:
2021-12-28 20:08:48 +00:00
```
2022-02-02 04:51:51 +00:00
$ cd python/web
2021-12-27 06:00:29 +00:00
$ source venv/bin/activate
$ pybabel --help
2021-12-28 20:08:48 +00:00
```
2021-12-27 06:00:29 +00:00
2021-12-28 20:08:48 +00:00
To create a new localization, it needs to be added to the LANGAUGES constant in
web/settings.py. To localize messages coming from the RaSCSI backend, update also code in
raspberrypi/localizer.cpp in the RaSCSI C++ code.
2021-12-26 21:36:12 +00:00
2022-08-05 14:30:20 +00:00
Once this is done, it is time to localize the Python code. The below steps are derived from the [Flask-Babel documentation ](https://python-babel.github.io/flask-babel/index.html#translating-applications ).
2022-05-02 19:42:09 +00:00
First, generate the raw messages.pot file containing extracted strings.
```
$ pybabel extract -F babel.cfg -o messages.pot .
```
### Initialize a new localization
When adding a localization for a new language, initialize the directory structure. Replace 'xx' with the two character code for the language.
```
2022-08-05 14:30:20 +00:00
$ pybabel init -i messages.pot -d src/translations -l xx
2022-05-02 19:42:09 +00:00
```
### Update an existing loclization
After strings have been added or changed in the code, update the existing localizations.
```
pybabel update -i messages.pot -d src/translations
```
2021-12-26 21:36:12 +00:00
2022-05-02 19:42:09 +00:00
Then edit the updated messages.po file for your language. Make sure to update fuzzy strings and translate new ones.
2021-12-27 06:00:29 +00:00
When you are ready to contribute new or updated localizations, use the same Gitflow Workflow as used for any code contributions to submit PRs against the develop branch.
2021-12-28 20:08:48 +00:00
### Working with PO files
See the [GNU gettext documentation ](https://www.gnu.org/software/gettext/manual/html_node/PO-Files.html ) for an introduction to the PO file format.
We make heavy use of __python-format__ for formatting, for instance:
```
#: file_cmds.py:353
#, python-format
msgid "%(file_name)s downloaded to %(save_dir)s"
msgstr "Laddade ner %(file_name)s till %(save_dir)s"
```
There are also a few instances of formatting in JavaScript:
```
#: templates/index.html:381
msgid "Server responded with code: {{statusCode}}"
msgstr "Servern svarade med kod: {{statusCode}}"
```
And with html tags:
```
#: templates/index.html:304
#, python-format
msgid ""
"Emulates a SCSI DaynaPORT Ethernet Adapter. < a href = \"%(url)s \"> Host "
"drivers and configuration required< / a > ."
msgstr ""
"Emulerar en SCSI DaynaPORT ethernet-adapter. < a href = \"%(url)s \"> Kräver "
"drivrutiner och inställningar< / a > ."
```
2022-08-26 00:57:44 +00:00
### Contributing to the project
New or updated localizations are treated just like any other code change. See the [project README ](https://github.com/akuker/RASCSI/tree/rdmark-readme-contributions#how-do-i-contribute ) for further information.
2021-12-27 06:00:29 +00:00
### (Optional) See translation stats for a localization
Install the gettext package and use msgfmt to see the translation progress.
2021-12-28 20:08:48 +00:00
```
2021-12-27 06:00:29 +00:00
$ sudo apt install gettext
2022-02-02 04:51:51 +00:00
$ cd python/web/src
2021-12-27 06:00:29 +00:00
$ msgfmt --statistics translations/sv/LC_MESSAGES/messages.po
2021-12-27 21:21:06 +00:00
215 translated messages, 1 untranslated message.
2021-12-28 20:08:48 +00:00
```