Skip to content
Snippets Groups Projects
Commit 7187016e authored by Tor-Einar Skog's avatar Tor-Einar Skog
Browse files

Translations system ready

parent 917007a7
No related branches found
No related tags found
No related merge requests found
...@@ -44,4 +44,27 @@ bumpver update --major ...@@ -44,4 +44,27 @@ bumpver update --major
[(Source)](https://semver.org/#summary) [(Source)](https://semver.org/#summary)
## References ## References
We used this excellent guide for packaging: https://realpython.com/pypi-publish-python-package/ We used this excellent guide for packaging: https://realpython.com/pypi-publish-python-package/
\ No newline at end of file
## Translations
We're using a simple dictionary translation system, with a module translations.py, where we
simply define some dictionaries with language codes as property, looking like this:
```python
name = {
"en": "Reference Model",
"nb": "Referansemodell",
}
```
This is used in the main module like this:
```python
[...]
from . import translations
[...]
def get_model_name(self, language = VIPSModel.default_language) -> str:
"""Returns the model name in the specified language (<a href="http://www.loc.gov/standards/iso639-2/php/English_list.php">ISO-639-2</a>)"""
return translations.name.get(language, translations.name.get(VIPSModel.default_language, "NOT FOUND"))
[...]
```
\ No newline at end of file
...@@ -21,7 +21,8 @@ along with VIPSCore-Python-Common. If not, see <http://www.nibio.no/licenses/>. ...@@ -21,7 +21,8 @@ along with VIPSCore-Python-Common. If not, see <http://www.nibio.no/licenses/>.
from vipscore_common.vips_model import VIPSModel from vipscore_common.vips_model import VIPSModel
from vipscore_common.entities import Result, ModelConfiguration, WeatherObservation from vipscore_common.entities import Result, ModelConfiguration, WeatherObservation
from vipscore_common.data_utils import * from vipscore_common.data_utils import *
import numpy as np from . import translations
class ReferenceModel(VIPSModel): class ReferenceModel(VIPSModel):
""" """
...@@ -125,7 +126,7 @@ class ReferenceModel(VIPSModel): ...@@ -125,7 +126,7 @@ class ReferenceModel(VIPSModel):
def get_model_name(self, language = VIPSModel.default_language) -> str: def get_model_name(self, language = VIPSModel.default_language) -> str:
"""Returns the model name in the specified language (<a href="http://www.loc.gov/standards/iso639-2/php/English_list.php">ISO-639-2</a>)""" """Returns the model name in the specified language (<a href="http://www.loc.gov/standards/iso639-2/php/English_list.php">ISO-639-2</a>)"""
return "Reference Model" return translations.name.get(language, translations.name.get(VIPSModel.default_language, "NOT FOUND"))
def get_model_description(self, language = VIPSModel.default_language) -> str: def get_model_description(self, language = VIPSModel.default_language) -> str:
"""Returns the model description in the specified language (<a href="http://www.loc.gov/standards/iso639-2/php/English_list.php">ISO-639-2</a>)""" """Returns the model description in the specified language (<a href="http://www.loc.gov/standards/iso639-2/php/English_list.php">ISO-639-2</a>)"""
...@@ -136,16 +137,10 @@ class ReferenceModel(VIPSModel): ...@@ -136,16 +137,10 @@ class ReferenceModel(VIPSModel):
def get_warning_status_interpretation(self, language = VIPSModel.default_language) -> str: def get_warning_status_interpretation(self, language = VIPSModel.default_language) -> str:
"""How to interpret the warning status (red-yellow-green, what does it mean?) in the specified language (<a href="http://www.loc.gov/standards/iso639-2/php/English_list.php">ISO-639-2</a>)""" """How to interpret the warning status (red-yellow-green, what does it mean?) in the specified language (<a href="http://www.loc.gov/standards/iso639-2/php/English_list.php">ISO-639-2</a>)"""
return """ return translations.wsi.get(language, translations.wsi.get(VIPSModel.default_language, "NOT FOUND"))
Gray status (warning status == 0): Warning not applicable
Blue status (warning status == 1): Missing data
Green status (warning status == 2): No risk. Sleep well
Yellow status (warning status == 3): The day-degree hreshold for medium risk has been passed. Be on the alert, inspect your field
Red status (warning status == 4): The day-degree threshold for high risk has been passed. When the going gets tough, the tough get going
"""
def get_model_usage(self, language = VIPSModel.default_language) -> str: def get_model_usage(self, language = VIPSModel.default_language) -> str:
"""Technical manual for this model, in the specified language (<a href="http://www.loc.gov/standards/iso639-2/php/English_list.php">ISO-639-2</a>)""" """Technical manual for this model, in the specified language (<a href="http://www.loc.gov/standards/iso639-2/php/English_list.php">ISO-639-2</a>)"""
return "TODO" return translations.usage.get(language, translations.usage.get(VIPSModel.default_language, "NOT FOUND"))
\ No newline at end of file
"""
Example translation system
"""
name = {
"en": "Reference Model",
"nb": "Referansemodell",
}
description = {
"en": """
Well, there's egg and bacon,
Egg sausage and bacon
Egg and spam
Egg, bacon and spam
Egg, bacon, sausage and spam
Spam, bacon, sausage and spam
Spam, egg, spam, spam, bacon and spam
Spam, sausage, spam, spam, spam, bacon, spam tomato and spam
Spam, spam, spam, egg and spam
Spam, spam, spam, spam, spam, spam, baked beans, spam, spam, spam and spam.
""",
"nb": """
Vel, det er egg og bacon,
Eggepølse og bacon
Egg og spam
Egg, bacon og spam
Egg, bacon, pølse og spam
Spam, bacon, pølse og spam
Spam, egg, spam, spam, bacon og spam
Spam, pølse, spam, spam, spam, bacon, spam tomat og spam
Spam, spam, spam, egg og spam
Spam, spam, spam, spam, spam, spam, baked beans, spam, spam, spam og spam.
""",
}
wsi = {
"en": """
Gray status (warning status == 0): Warning not applicable
Blue status (warning status == 1): Missing data
Green status (warning status == 2): No risk. Sleep well
Yellow status (warning status == 3): The day-degree hreshold for medium risk has been passed. Be on the alert, inspect your field
Red status (warning status == 4): The day-degree threshold for high risk has been passed. When the going gets tough, the tough get going
""",
"nb": """
Grå status (advarselsstatus == 0): Advarsel ikke aktuelt
Blå status (advarselsstatus == 1): Manglende data
Grønn status (advarselsstatus == 2): Ingen risiko. Sov godt
Gul status (advarselsstatus == 3): Daggradsterskelen for middels risiko er passert. Vær på vakt, inspiser feltet ditt
Rød status (advarselsstatus == 4): Daggradsterskelen for høy risiko er passert. Når det blir tøft, kommer de tøffe i gang
"""
}
usage = {
"en": """
Input data are:
sowingDate (yyyy-MM-dd) - the day you sowed your crop
timeZone - the timeZone you're in, e.g. "Europe/Oslo"
weatherData - daily mean temperatures in degrees Celcius
""",
"nb": """
Inndata er:
sådato (åååå-MM-dd) - dagen du sådde avlingen
tidssone - tidssonen du er i, f.eks. "Europe/Oslo"
værdata - daglig gjennomsnittstemperatur i grader Celsius
"""
}
\ No newline at end of file
...@@ -75,6 +75,8 @@ class TestReferenceModel(unittest.TestCase): ...@@ -75,6 +75,8 @@ class TestReferenceModel(unittest.TestCase):
""" """
instance = ReferenceModel() instance = ReferenceModel()
self.assertEqual(instance.get_model_name(), "Reference Model") self.assertEqual(instance.get_model_name(), "Reference Model")
# Norwegian
self.assertEqual(instance.get_model_name("nb"), "Referansemodell")
def test_get_model_description(self): def test_get_model_description(self):
""" """
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment