Skip to content

Commit bf8b3cd

Browse files
wip: translate indicator description
1 parent 1cecda4 commit bf8b3cd

File tree

5 files changed

+2857
-3
lines changed

5 files changed

+2857
-3
lines changed

ohsome_quality_api/indicators/models.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from datetime import datetime, timezone
22
from typing import Literal
33

4-
from pydantic import BaseModel, ConfigDict, Field, computed_field
4+
from fastapi_i18n import _
5+
from pydantic import BaseModel, ConfigDict, Field, computed_field, field_validator
56

67
from ohsome_quality_api.projects.definitions import ProjectEnum
78
from ohsome_quality_api.quality_dimensions.definitions import QualityDimensionEnum
@@ -18,11 +19,16 @@ class IndicatorMetadata(BaseModel):
1819
model_config = ConfigDict(
1920
alias_generator=snake_to_lower_camel,
2021
title="Metadata",
21-
frozen=True,
22+
# frozen=True, # TODO: re-enable
2223
extra="forbid",
2324
populate_by_name=True,
2425
)
2526

27+
@field_validator("name", "description", mode="before")
28+
@classmethod
29+
def translate(cls, value: str) -> str:
30+
return _(value)
31+
2632

2733
class IndicatorTemplates(BaseModel):
2834
"""Result text templates of an indicator as defined in the templates.yaml file."""

ohsome_quality_api/locale/de/LC_MESSAGES/messages.po

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ msgstr ""
287287
msgid ""
288288
"Calculate if mapping has saturated. High saturation has been reached if "
289289
"the growth of the fitted curve is minimal."
290-
msgstr ""
290+
msgstr "Berechne ob das Kartieren gesättigt ist. Bei hohe Sättigung ist die Steigung der Kurve minimal."
291291

292292
#: ohsome_quality_api/indicators/indicators.yaml
293293
msgid "Density"
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from approvaltests import verify
2+
3+
from tests.integrationtests.utils import oqapi_vcr
4+
5+
ENDPOINT = "/indicators/"
6+
7+
# TODO
8+
# Test fallback to en if no translation string found -> Use non existent language.
9+
# Test if no accept-language header is setenv.
10+
# Test result description
11+
# Test result figure
12+
# Remove and recreate VCR cassette for this test
13+
14+
15+
@oqapi_vcr.use_cassette
16+
def test_indicators(client, bpolys, monkeypatch):
17+
monkeypatch.setenv(
18+
"FASTAPI_I18N_LOCALE_DIR",
19+
"/home/matthias/work/projects/oqapi/ohsome_quality_api/locale",
20+
)
21+
endpoint = "/indicators/mapping-saturation"
22+
parameters = {
23+
"bpolys": bpolys,
24+
"topic": "building-count",
25+
}
26+
response = client.post(
27+
endpoint,
28+
json=parameters,
29+
headers={"Accept-Language": "de", "accept": "application/json"},
30+
)
31+
result = response.json()
32+
verify(result["result"][0]["metadata"]["description"])
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Berechne ob das Kartieren gesättigt ist. Bei hohe Sättigung ist die Steigung der Kurve minimal.

tests/integrationtests/fixtures/vcr_cassettes/api/test_i18n.yaml

Lines changed: 2815 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)