Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Possibility to modify the key #27

Open
mdumrauf opened this issue Jan 14, 2016 · 0 comments
Open

Possibility to modify the key #27

mdumrauf opened this issue Jan 14, 2016 · 0 comments

Comments

@mdumrauf
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant