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

Missing phrases after import #111

Open
LorensoD opened this issue May 7, 2024 · 4 comments · May be fixed by #155
Open

Missing phrases after import #111

LorensoD opened this issue May 7, 2024 · 4 comments · May be fixed by #155

Comments

@LorensoD
Copy link

LorensoD commented May 7, 2024

I've identified a potential issue in the ImportTranslationsCommand, specifically within the syncMissingTranslations() function. The function is designed to create a new phrase in the specified locale if it doesn't already exist, but only if it exists in the source locale. However, the current implementation may not correctly handle phrases across different translation files.

Current Implementation:

The existing code checks if a phrase with the same key exists in the specified locale, but it doesn't consider the translation group (file) the phrase belongs to. The relevant code is on line 130:

if (! $translation->phrases()->where('key', $phrase->key)->first()) {

Issue:

This approach can lead to inaccuracies where phrases from different groups might get conflated if they share the same key. This was apparent after some phrases were missing in my non-source languages when importing translation strings.

Proposed Change:

To address this issue, I suggest modifying the check to include the translation group. This ensures the uniqueness of phrases is respected not just by key but also by the group they belong to. The code would then look like this:

if (! $translation->phrases()->where('group', $phrase->group)->where('key', $phrase->key)->first()) {

Additional Note:

This adjustment should also be mirrored in the SyncPhrasesAction:52.

@digitalcraftlabs
Copy link

I have the same problem. I will create a PR for it and hopefully get it merged as soon as possible.

@caswd
Copy link
Contributor

caswd commented Feb 12, 2025

@digitalcraftlabs I see your PR was not approved... I created one that works for me locally. Could you please take a look?

@digitalcraftlabs
Copy link

@caswd That's not a problem. But I can explain what this part does exactly. After creating an element, we need to map it to a similar element with the same key. This means that the key can exist in other files, which is why we don't need to add the group condition.

@caswd
Copy link
Contributor

caswd commented Feb 13, 2025

@digitalcraftlabs maybe my issue is different from yours...

I have a structure like:

lang/
    en/
        authors.php
        posts.php

authors.php looks like this:

return [
    'page_title' => 'Authors',
];

posts.php looks like this:

return [
    'page_title' => 'Posts',
];

When I load it into my database with translations for 'en' and 'nl' (Dutch), the ltu_phrases table looks like:

id translation_id phrase_id key group
1 1 null page_title authors
2 1 null page_title posts
3 2 1 page_title authors

As you can see, I am missing the Dutch phrase for posts.page_title. This is because the query that creates the missing ltu_phrases in the database only check for key, and the key page_title does indeed already exist for the Dutch locale.

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