Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Preserve quote style while changing a YAML file #671

Open
marselmustafin opened this issue May 24, 2024 · 0 comments
Open

Preserve quote style while changing a YAML file #671

marselmustafin opened this issue May 24, 2024 · 0 comments

Comments

@marselmustafin
Copy link

I have Rails I18n en.yml file which contains values with or without qoutes.

I want to change this file programmatically, but if I use Psych#load and Psych#dump approach it removes all the quotes from values. I don't want to change styling of existing values, how can I do that?

As I understand parsing the ast is the way, but I want to preserve simplicity of working with YAML as the hash and then simply dump it back as the original file but with a few new key/values.

Input:

en:
  account:
    invoices:
      empty: 'It''s empty here'
      tabs:
        donations: Donations
        giftcards: 'Gift Cards'
        membership: Membership
        purchases: Purchases
        subscription: Subscription
      title: 'Invoices History'

Expected result (all styling preserved, new key added):

en:
  account:
    invoices:
      empty: 'It''s empty here'
      tabs:
        donations: Donations
        giftcards: 'Gift Cards'
        membership: Membership
        purchases: Purchases
        subscription: Subscription
        my_new_key: New Value
      title: 'Invoices History'
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Development

No branches or pull requests

1 participant