Skip to content

composability of translations from different packages #20

@stevengj

Description

@stevengj

The one thing I've been worried about is how _"..." strings compose within Julia's package system, because they currently use the global textdomain setting.

  • One perspective is that most individual packages shouldn't need translations, because they don't provide user interfaces — this is only done at the top application level. So there is only a single translation "domain" for the application.
  • However, there are packages that open up user interface windows, like @timholy's ImageView.jl package — shouldn't each such package be able to have its own translations, in its own po directory?

One option is for _"..." to expand to gettext(GETTEXT_DOMAIN, "..."), where GETTEXT_DOMAIN is somehow relative to the current @__MODULE__. e.g. we could require that any module using _"..." defines a constant GETTEXT_DOMAIN to be the domain string.

That is, to use _"..." in a package, you would do something like:

module Foo
using Gettext

const GETTEXT_DOMAIN = "Foo-<uuid>"
function __init__()
    bindtextdomain(GETTEXT_DOMAIN, joinpath(@__DIR__, "..", "po"))
end

# ...
end

at which point _"..." should work, but you would have to explicitly pass GETTEXT_DOMAIN to ngettext etc. I guess we could define an @ngettext macro that does this for you.

The above still seems a little awkward, though. Not sure what the cleanest solution is here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions