airblade / vim-localorie

A Vim plugin for easy look-up of translations for Rails i18n YAML keys.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

No translations for ... (with yaml references)

gingerlime opened this issue · comments

It's probably way too much to ask, but I noticed that when we use yaml references, I'm getting "No translations for...".

For example:

en:
  payment:
    subscription:
      faq: &pricing_faq
        question: a question
    stripe_subscription:
      faq:
        <<: *pricing_faq

When I'm inside app/views/payment/stripe_subscription.html.haml and look up a key like .faq.question

Is there a way to make it work?

Or maybe it's a problem unrelated to yaml references? (hope the video is legible...)

CleanShot 2022-02-16 at 13 28 37

There's no easy way for the plugin to follow or de-reference YAML anchors. The current implementation reads each locale file from bottom to top and extracts keys and values with a regex.

However the presence of an anchor shouldn't prevent nested keys from being read. I'll fix up the regex.

Thanks for the super quick reply!

I guess it's tricky or impossible with vim scripting, or without introducing an external dependency ... but if you are able to use a yaml parser, then it should hopefully do most of the legwork for you?

3541ff2 fixes the problem where an anchor would "block" the children.

However aliases still won't be de-referenced.

I do not want to use a YAML parser: third-party dependencies add complexity, reduce compatibility, and introduce never-ending support problems!

However it may be possible to support aliases anyway. I'll have a think.

Thank you @airblade. Yes, I completely understand. It's a trade-off. I guess you can get very far without a full parser, but YAML is a pretty complex beast, so having someone take care of all the headache can be tempting for sure :)

Thanks again for your help. I really appreciate it. Looking forward to use the plugin. It's already very helpful.

The main problem with a third-party YAML parser, which I forgot to mention above, is that they generally don't report the line numbers where each value comes from. And without the line number you don't know where to jump to in the locale file.

Originally I used a monkey-patched Ruby parser but I replaced it in fd4d751.

Anyway, 8611926 adds support for anchors, aliases, and merge keys so it should solve your issue.

That's incredible. Thank you so much @airblade! Can't wait to use the new version. And yes, you're absolutely right about the limitations of a yaml parser. It didn't occur to me, but makes perfect sense. Thank you!