Dne 8.8.2013 11:59, Jiří Suchomel napsal(a):
> V Thu, 08 Aug 2013 08:18:01 +0200
> Ladislav Slezak <[email protected]> napsáno:
[...]
> Still not usable for data files of yast2-country: currently there are
> explicitly loaded via target.ycp each time when the language is
> changed so the new translation is available during run-time.
> 
> I guess we cannot force load the include file when we need to
> re-translate those files. Is there any ruby solution for that?

A possible solution could be to wrap the YAML in an ERB template,
in ERB you can put any Ruby code:

  foo.yml.erb:
    ---
    foo: <%= _("bar") %>

Then it could be read using

  YAML.load(ERB.new(File.read("foo.yml.erb")).result)

(See e.g. http://urgetopunt.com/rails/2009/09/12/yaml-config-with-erb.html)

Ruby Gettext even supports ERB, so it should be easy to extract translatable 
strings
from ERB files.

But the example is not complete, we would need to "escape" the translated 
string to
make sure not to break the YAML format...


Another possibility is to use a user data type feature in YAML, you can actually
convert any object to YAML:

  Object.new.to_yaml => "--- !ruby/object {}\n"


We could create e.g. TranslatableString class which would handle translations.

But in this case extracting the translatable texts from YAML would be 
complicated,
we would likely need a new specific parser for that.


(BTW in both cases the YAML files became unportable, you cannot read them using 
e.g.
perl-YAML library or something else. But that should not be a problem, YCP files
were unreadable outside Yast anyway...)


I already discussed that in the past with Josef, he told me that it should be 
somehow
possible to use translations in YAML files. So let's see when he's
back from vacation...


--

Ladislav Slezák
Appliance department / YaST Developer
Lihovarská 1060/12
190 00 Prague 9 / Czech Republic
tel: +420 284 028 960
[email protected]
SUSE
-- 
To unsubscribe, e-mail: [email protected]
To contact the owner, e-mail: [email protected]

Reply via email to