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

Stabilize parser output by forcing the key as a string context #89

Closed
iafan opened this issue Nov 5, 2018 · 3 comments
Closed

Stabilize parser output by forcing the key as a string context #89

iafan opened this issue Nov 5, 2018 · 3 comments

Comments

@iafan
Copy link
Contributor

iafan commented Nov 5, 2018

By default, when parsing a file, context string is generated only when necessary when there are multiple identical strings in a file. In this case, the first occurrence of the string doesn't have the context, while others do. However, if a new identical string is inserted at the beginning of the file, it will become the one with no context, while the next one will now suddenly get a context string, making it a new unit, and it's translation will be reset (or reused based on Serge settings). This behavior is especially undesirable when using the feature_branch plugin, where string+context pairs are compared between branches to filter out the pairs that are shared between branches.

To stabilize the output, it makes sense to introduce the use_keys_as_context boolean flag in the job scope, defaulting to NO for backward-compatibility. When set to YES, all string keys reported by the parser will be copied over to the context, unless context was explicitly provided by the parser. This would guarantee in the situations described above that the units are stable even if the strings in the resource file are shuffled around, provided the resource file itself has stable string keys.

@dragosv
Copy link
Contributor

dragosv commented Nov 14, 2018

Can you give more specific examples?

@iafan
Copy link
Contributor Author

iafan commented Nov 14, 2018

An example would be the master branch having the following resource:

key1=foo
key2=foo

and a feature branch having the following one:

key0=foo
key1=foo
key2=foo

In these two branches strings key1=foo and key0=foo will have no context and will be considered the same by a feature_branch plugin. So what will be exposed for translation is:

master:

  • 'foo' (empty context)
  • 'foo' ('key2' context)

branch:

  • 'foo' ('key1' context)

which is incorrect. Forcing the context would yield proper results:

master:

  • 'foo' ('key1' context)
  • 'foo' ('key2' context)

branch:

  • 'foo' ('key0' context)

@iafan
Copy link
Contributor Author

iafan commented Jul 22, 2019

Implemented, closing.

@iafan iafan closed this as completed Jul 22, 2019
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

2 participants