Skip to content

Possibility to modify the key #27

@mdumrauf

Description

@mdumrauf

Scenario: need to parse a Localizable.strings file from an iOS project which looks like this

/* Some useful comments */
"LOGIN_TEXT_LOGIN" = "Login";
"LOGIN_TEXT_PASSWORD" = "Password";
"LOGIN_FIRSTNAME" = "First Name";

I can modify the options to use a specific character for comments and a reviver to modify the value:

var options = {
  path:true,
  comments: '/',
  separators: '=',
  strict: true,
  reviver: function(key, value, section) {
    return value.replace(/^"|";$/g, '');
  }
};
properties.parse('en.lproj/Localizable.strings', options, function(error, obj) {
  console.log(obj);
});

And obtain this output:

{
  '"LOGIN_TEXT_LOGIN"': 'Login',
  '"LOGIN_TEXT_PASSWORD"': 'Password',
  '"LOGIN_FIRSTNAME"': 'First Name'
}

However, the key still needs some tuning. For now, I am replacing the " before using the object, but it would nice to be able to return a json in the modifier that could be the new tuple key|value|section.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions