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

Make language mappings deterministic #241

Merged
merged 1 commit into from
Sep 4, 2024

Conversation

kbairak
Copy link
Member

@kbairak kbairak commented Sep 4, 2024

Consider this scenario: Someone has in their config file:

[main]
lang_map = it: it-IT

[RESOURCE_ID]
lang_map = it: it_IT

Before we created a local-to-remote map that looked like this:

{"it-IT": "it", "it_IT", "it"}

And then, to create the remote-to-local map, we reversed it. The problem was that, since both values are the same, the key that ended up being selected was random, so it could either be:

{"it": "it-IT"}

or

{"it": "it_IT"}

To fix the issue, we now create remote-to-local first, going over the global configuration first and the resource-level configuration second so that the resource-level will prevail and thus take preference, and then we create the local-to-remote by reversing. So,

First, we will consume the global configuration:

{"it": "it-IT"}

Then, as the resource-level configuration is consumed, it will replace the old key:

{"it": "it_IT"}

And then, the local-to-remote will end up being:

{"it_IT": "it"}

This is the deterministic and the intended behaviour, since resource-level configuration should take precedence.

@kbairak kbairak force-pushed the TX-15697-fix_language_mappings branch from 21ee013 to c4430f8 Compare September 4, 2024 12:33
Consider this scenario: Someone has in their config file:

```ini
[main]
lang_map = it: it-IT

[RESOURCE_ID]
lang_map = it: it_IT
```

Before we created a local-to-remote map that looked like this:

```json
{"it-IT": "it", "it_IT", "it"}
```

And then, to create the remote-to-local map, we reversed it. The problem
was that, since both values are the same, the key that ended up being
selected was random, so it could either be:

```json
{"it": "it-IT"}
```

or

```json
{"it": "it_IT"}
```

To fix the issue, we now create remote-to-local first, going over the
global configuration first and the resource-level configuration second
so that the resource-level will prevail and thus take preference, and
then we create the local-to-remote by reversing. So,

First, we will consume the global configuration:

```json
{"it": "it-IT"}
```

Then, as the resource-level configuration is consumed, it will replace
the old key:

```json
{"it": "it_IT"}
```

And then, the local-to-remote will end up being:

```json
{"it_IT": "it"}
```

This is the deterministic and the intended behaviour, since
resource-level configuration should take precedence.
Copy link
Contributor

@foteinigk foteinigk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Changes work as expected!!🚀

@kbairak kbairak merged commit e7feea3 into devel Sep 4, 2024
6 checks passed
@kbairak kbairak deleted the TX-15697-fix_language_mappings branch September 4, 2024 13:17
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

Successfully merging this pull request may close these issues.

2 participants