Open wjordan opened 10 years ago
It would take a bit of refactoring to the C extension to leverage Psych (or more accurately libyaml). It is on my todo list, but I don't have an ETA for it yet.
That said, Psych and Syck can live along side each other. For example, I've got a Rails 4.1 app (Ruby 2) that uses the built-in Psych for any YAMLy stuff, yet I18nema is able to use Syck:
irb(main):014:0> I18n.backend
=> #<I18nema::Backend:0x007f9a847ed198 @translations=#<I18nema::Backend:0x007f9a898c9ee0>, @normalized_key_cache=#<I18nema::Backend:0x007f9a898c9e68>, @initialized=true>
irb(main):015:0> I18n.backend.direct_lookup("en", "hello")
=> "Hello world"
irb(main):016:0> YAML.parse('foo: bar')
=> #<Psych::Nodes::Document:0x007f9a8382aeb8 @children=[#<Psych::Nodes::Mapping:0x007f9a8382ae68 @children=[#<Psych::Nodes::Scalar:0x007f9a8382adf0 @value="foo", @anchor=nil, @tag=nil, @plain=true, @quoted=false, @style=1>, #<Psych::Nodes::Scalar:0x007f9a8382ada0 @value="bar", @anchor=nil, @tag=nil, @plain=true, @quoted=false, @style=1>], @anchor=nil, @tag=nil, @implicit=true, @style=1>], @version=[], @tag_directives=[], @implicit=true, @implicit_end=true>
But yeah, it's something I plan to support so you don't have to have both installed.
A related issue using I18nema alongside Psych is that the to_yaml
methods end up using the Syck engine by default, even if the YAML::ENGINE.yamler
property is overridden. Here's a workaround we had to add to an initializer in order to have to_yaml
method find the Psych engine as expected:
YAML::ENGINE.yamler = 'psych'
# We need to remove the :to_yaml methods Syck injects into certain classes (Psych only uses Object::to_yaml)
# Class list is from syck-1.0.1/lib/syck/rubytypes.rb
%w(Class Hash Struct Array Exception String Symbol Range Regexp
Time Date Integer Float Rational Complex TrueClass FalseClass NilClass).each do |x|
x.constantize.send(:remove_method, :to_yaml) if x.constantize.instance_methods(false).include?(:to_yaml)
end
The workaround doesn't seem to work anymore since Ruby 2.2: https://github.com/ruby/syck/issues/9
unfortunately, this project is no longer supported. we haven't used it internally for ~5 years, in favor of just using the regular i18n gem. it never made the jump to Psych, and hasn't been a high enough priority to maintain. feel free to fork it and continue using it yourself.
What would be required for this backend to support projects that currently depend on the psych YAML parser? I have a project that could definitely benefit from this faster i18n backend, but it seems like syck is a requirement.