Given the simple YAML file for localisation:
root:
label: \'Test\'
account: \'Account\'
add: \'Add\'
local_folder: \'Local folder\'
remote_folder: \'Re
require 'yaml'
str = <<-eol
root:
label: 'Test'
account: 'Account'
add: 'Add'
local_folder: 'Local folder'
remote_folder: 'Remote folder'
status: 'Status'
subkey: 'Some value'
eol
h = YAML.load(str)
h["root"]["local_folder"] = h["root"]["local_folder"] + " !Test comment"
h["root"]["subkey"] = h["root"]["subkey"] + " !Test comment"
puts h.to_yaml
# >> ---
# >> root:
# >> label: Test
# >> account: Account
# >> add: Add
# >> local_folder: Local folder !Test comment
# >> remote_folder: Remote folder
# >> status: Status
# >> subkey: Some value !Test comment
EDIT
more programmatically:
require 'yaml'
str = <<-eol
root:
label: 'Test'
account: 'Account'
add: 'Add'
local_folder: 'Local folder'
remote_folder: 'Remote folder'
status: 'Status'
subkey: 'Some value'
eol
h = YAML.load(str)
%w(local_folder subkey).each {|i| h["root"][i] = h["root"][i] + " !Test comment" }
puts h.to_yaml
# >> ---
# >> root:
# >> label: Test
# >> account: Account
# >> add: Add
# >> local_folder: Local folder !Test comment
# >> remote_folder: Remote folder
# >> status: Status
# >> subkey: Some value !Test comment