-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
236 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
FROM node:20-alpine as ui_builder | ||
|
||
RUN apk --no-cache add yarn | ||
WORKDIR /src/ui | ||
COPY ui/package.json ui/yarn.lock /src/ui/ | ||
RUN yarn install | ||
COPY ui/index.html /src/ui/ | ||
COPY ui/*.json /src/ui/ | ||
COPY ui/*.ts /src/ui/ | ||
COPY ui/*.js /src/ui/ | ||
COPY ui/public /src/ui/public | ||
COPY ui/src /src/ui/src | ||
COPY locales /src/locales | ||
RUN NODE_ENV=production yarn build | ||
|
||
|
||
FROM caddy:2.8-alpine | ||
LABEL org.opencontainers.image.source https://github.com/openzim/zimit-frontend | ||
|
||
COPY --from=ui_builder /src/ui/dist /usr/share/caddy | ||
|
||
COPY locales /locales |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,37 @@ | ||
from pathlib import Path | ||
from typing import Any | ||
|
||
import i18n | ||
import i18n # pyright: ignore | ||
|
||
from zimitfrontend.constants import logger | ||
from zimitfrontend.constants import ApiConfiguration, logger | ||
|
||
|
||
def setup_i18n(): | ||
def setup_i18n() -> None: | ||
"""Configure python-i18n""" | ||
i18n.set("locale", "en") | ||
i18n.set("fallback", "en") | ||
i18n.set("file_format", "json") | ||
i18n.set("filename_format", "{locale}.{format}") | ||
i18n.set("skip_locale_root_data", True) | ||
|
||
prod_folder = Path("/locales") | ||
if prod_folder.exists(): | ||
logger.info(f"Loading locales from {prod_folder}") | ||
i18n.load_path.append(prod_folder) | ||
|
||
dev_folder = Path(Path(__file__).parent.parent.parent.parent / "locales") | ||
if dev_folder.exists(): | ||
logger.info(f"Loading locales from {dev_folder}") | ||
i18n.load_path.append(dev_folder) | ||
|
||
|
||
def set_locale(lang): | ||
i18n.set("locale", "en") # pyright: ignore[reportUnknownMemberType] | ||
i18n.set("fallback", "en") # pyright: ignore[reportUnknownMemberType] | ||
i18n.set("file_format", "json") # pyright: ignore[reportUnknownMemberType] | ||
i18n.set( # pyright: ignore[reportUnknownMemberType] | ||
"filename_format", "{locale}.{format}" | ||
) | ||
i18n.set("skip_locale_root_data", True) # pyright: ignore[reportUnknownMemberType] | ||
|
||
locales_location = Path(ApiConfiguration.locales_location) | ||
if not locales_location.exists(): | ||
raise Exception(f"Missing locales folder '{locales_location}'") | ||
logger.info(f"Loading locales from {locales_location}") | ||
i18n.load_path.append(locales_location) # pyright: ignore | ||
|
||
|
||
def change_locale(lang: str) -> None: | ||
"""Change locale""" | ||
i18n.set("locale", lang) | ||
i18n.set("locale", lang) # pyright: ignore[reportUnknownMemberType] | ||
|
||
|
||
def t(key, **kwargs): | ||
def t(key: str, **kwargs: Any) -> str: | ||
"""Get translated string""" | ||
return i18n.t(key, **kwargs) | ||
return ( | ||
i18n.t( # pyright: ignore[reportUnknownMemberType, reportUnknownVariableType] | ||
key, **kwargs | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.