[katello-devel] How to format strings
Lukas Zapletal
lzap at redhat.com
Fri Sep 21 07:42:36 UTC 2012
On Fri, Sep 21, 2012 at 09:20:18AM +0200, Miroslav Suchy wrote:
> In our code base we use very frequently:
>
> _("Couldn't find changeset '#{params[:changeset_id]}'")
>
> and later:
>
> _("Couldn't find changeset '#{params[:id]}'")
>
> But this notation means that the name of variable is part of string
> to be translated. And that results in two strings, which needs to be
> translated:
>
> msgid "\"Couldn't find changeset '#{params[:changeset_id]}'\""
> msgstr ""
>
> msgid "\"Couldn't find changeset '#{params[:id]}'\""
> msgstr ""
>
>
> Please if you are writing string, which you are passing to gettext
> function (aka _()), then user rather this notation:
>
> _("Couldn't find changeset '%s'") % params[:id]
>
> or
>
> _("Couldn't find changeset '%s' and '%s'") % [params[:id], foo]
>
> If we will follow this, we will significantly reduce number of
> strings to be translated.
>
> Thank you.
>
> P.S. I'm preparing pull request, which will unify these duplicities.
> I'm doing that in my spare time, so it will take some time.
>
There was a long discussion on the list in this regard and we have
agreed we will stick with #{} but only for simple variables. We should
avoid constructs like calling functions or hashes in this case.
> _("Couldn't find changeset '#{simplevar}'")
Because this gives translators better flexibility when there are
multiple substitutions. With %s they are not able to re-order those for
some languages.
I know there is a generic approach of numbering those, something like %1
%2 but after short investigation we have found this is not possible for
Ruby i18n libraries we use.
I think the plan was to write a simple checker that would watch the
codebase for invalid string interpolations. Correct me, if I am wrong.
https://fedorahosted.org/katello/wiki/I18N
--
Later,
Lukas "lzap" Zapletal
#katello #systemengine
More information about the katello-devel
mailing list