MichaelChirico / potools

Tools for working with translations in R
https://michaelchirico.github.io/potools/
58 stars 2 forks source link

Advice for translating collapsed lists? #233

Closed hadley closed 2 years ago

hadley commented 3 years ago

How should I translate code like this?

paste0("Source: " , paste(links, collapse = ", "))

I can translate just the Source, but presumably languages have different conventions for this.

Also worth considering glue::glue_collapse() or similar, which can generate phrases like "a, b, c, and d"

MichaelChirico commented 3 years ago

I think gettextf("Source: %s", toString(links)) would lead to the most translate-able template.

glue_collapse() is a bit tougher... maybe glue_collapse() itself should get a domain argument?

Tangentially related: Gergey Daróczi also raised the interesting idea of using glue templates and gettext() instead of gettextf():

gettext(glue::glue("Source: {link_list}"))
# or
gettext(glue::glue("Source: {toString(link_list)}")

Advantages:

Disadvantage:

hadley commented 3 years ago

I think you mean glue::glue(gettext("Source: {link_list}")), but yeah totally agreed. It's seems much easier to understand multi-component messages when the components are given named instead of numbers. I think that the downsides are small in practice.

toString() isn't localised either, but presumably punctuation is more consistent across (most modern) languages.

hadley commented 3 years ago

I asked on twitter to get a sense for how this differs. Here's a summary:

hadley commented 3 years ago

Comprehensive solution at https://github.com/rossellhayes/and

MichaelChirico commented 3 years ago

Looks great to be able to offload this to and. Should that be functionality in glue, though?

hadley commented 3 years ago

Yeah, I think it would make sense to either bundle the functionality with glue or with potools. It would be useful to have all translation related stuff in one place, but bundling it with potools would imply some packages would need to take a run-time dependency on potools and I don't know how you feel about that.

MichaelChirico commented 3 years ago

Right... it looks like and is more of a "recommended package" from potools perspective. With gettextf() potools would be basically agnostic to it:

gettextf("Valid arguments are: %s", toString(valid_args))
# vs
gettext(glue("Valid arguments are: {glue_collapse(valid_args)}"))
# vs
gettext(glue("Valid arguments are: {and(valid_args)}"))

So as I'm seeing it now, this could be Suggested & included in vignettes

hadley commented 3 years ago

Yeah good point. I'll leave this open to include in my vignette, but otherwise seems like there's nothing for potools to do.

hadley commented 3 years ago

Would have to think through the consequences of routinely using and() in glue strings; it would be weird to see Valid arguments are aやb、c if the rest of the string hasn't been translated.

MichaelChirico commented 3 years ago

Agreed... looks like, even for glue, the best approach is to recommend it (maybe in the glue_collapse() docs)