Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose public translations to the client #1322

Open
phorward opened this issue Nov 15, 2024 · 0 comments · May be fixed by #1323
Open

Expose public translations to the client #1322

phorward opened this issue Nov 15, 2024 · 0 comments · May be fixed by #1323
Labels
performance This issue or pull request enhances or criticizes the performance. Priority: High After critical issues are fixed, these should be dealt with before any further issues. security For security related bugs

Comments

@phorward
Copy link
Member

To implement client-side translations, there must be a way to expose translations of a given language to the client.

In several customer projects, it was done like this already:

    @exposed
    @as_json_response
    def get_current_translations(
        self,
        *,
        all_langs: bool = False,
        v: str | None = None,
    ) -> dict[str, str] | dict[str, dict[str, str]]:
        if (
            not (conf.debug.disable_cache and current.request.get().disableCache)
            and any(os.getenv("HTTP_HOST", "") in x for x in conf.i18n.domain_language_mapping)
        ):
            # cache it 7 days
            current.request.get().response.headers["Cache-Control"] = f"public, max-age={7 * 24 * 60 * 60}"
        if all_langs:
            return {
                lang: {tr_key: str(translate(tr_key, force_lang=lang))
                       for tr_key, values in systemTranslations.items()}
                for lang in conf.i18n.available_dialects
            }
        return {tr_key: str(translate(tr_key)) for tr_key, values in systemTranslations.items()}

This is both very non-performant, but also reveals translations of - maybe internal parts - publicly to any client.

An idea to resolve this would be to work either with a prefix, or with a public-flag on translations.

@phorward phorward added security For security related bugs Priority: High After critical issues are fixed, these should be dealt with before any further issues. performance This issue or pull request enhances or criticizes the performance. labels Nov 15, 2024
@phorward phorward added this to the ViUR-core v3.6 milestone Nov 15, 2024
@phorward phorward linked a pull request Nov 15, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance This issue or pull request enhances or criticizes the performance. Priority: High After critical issues are fixed, these should be dealt with before any further issues. security For security related bugs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant