Code Monkey home page Code Monkey logo

Comments (4)

MichaelHoste avatar MichaelHoste commented on September 13, 2024

Hi @skyporter,

Actually, YAML files are almost always prefixed by one, or maybe a couple of keys, but not more.

So if you want to completely ignore a YAML file you can add something like this:

config.ignored_key_prefixes = [
    'root_key_of_your_yaml_file.', # don't forget the trailing dot
 ]

If you happen to have a lot of first-level keys in your YAML file, you can still do something like this:

config.ignored_key_prefixes = YAML.load(File.read('config/locales/ignored.en.yml'))['en'].keys.collect { |k| "#{k}." }
# => ["admin.", "enumerize.", "activerecord."]

It's not "neat" but it should work too.

from rails.

skyporter avatar skyporter commented on September 13, 2024

Hi,

Thanks for the alternative suggestions, unfortunately not applicable to my case as I have a file that only contains backend translations.

For example, I have a Customer model which should be only translated in only one language. I manage that by storing "customers keys" on a dedicated file backend-activerecord.fr.yml:

fr:
  activerecord:
    models:
      customer:
        one: "Fiche client"
        other: "Fiches clients"

and my generic activerecord.fr.yml file contain all others keys:

fr:
  activerecord:
    models:
      user: Utilisateur
      ...

As suggested, my only alternative with translation.io is to do that:

  config.ignored_key_prefixes = [
    "activerecord.models.customer.",
    "activerecord.attributes.customer."
  ]

It would have been easier with the exclusion of the file.

from rails.

MichaelHoste avatar MichaelHoste commented on September 13, 2024

Now I understand why you need something like this.

That's not a very common YAML structure and I'm not sure we should add a new ignored_yaml_files configuration for this.

Wouldn't it possible for you to add a small helper method to ignore some specific keys of you models?

Something like this:

def ignore_for_backend(models)
  models.collect { |m| ["activerecord.models.#{m}.", "activerecord.attributes.#{m}."] }.flatten
end

config.ignored_key_prefixes = ignore_for_backend(['customer', 'projects'])

I'm going to leave that issue open.

We could consider adding this option if many users need it.

from rails.

skyporter avatar skyporter commented on September 13, 2024

Yes, I can probably code a script to automate this. Meanwhile, I can always add the keys one by one.
Thanks for your help.

from rails.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.