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

Translation list duplicated lines #86

Open
roolian opened this issue May 2, 2024 · 1 comment
Open

Translation list duplicated lines #86

roolian opened this issue May 2, 2024 · 1 comment

Comments

@roolian
Copy link

roolian commented May 2, 2024

Issue

After a scan, listing show the same string multiple times :

image

Edit

By adding this log in vendor/brackets/craftable-pro/src/Translations/Repositories/LanguageLineRepository.php

public function createLanguageLineIfDoesntExist($group, $key, $language = null, $text = null): LanguageLine | null
       {
            if (empty(trim($key))) {
                return null;
          }

        /** @var LanguageLine $translation */
        $languageLine = LanguageLine::withTrashed()
            ->where('group', $group)
            ->where('key', $key)
            ->first();


            if (str_contains($key, 'ame') && str_contains($key, 'irst')) {
                if ($languageLine) {
                    Log::info(["Scan: ".$group."/".$key, "Found key: ".$languageLine->key, $languageLine->key === $key ?  "Confirm match" : "New trans: ".$group."/".$key]);
                } else {
                    Log::info(["Scan: ".$group."/".$key, "New trans: ".$group."/".$key]);
                }
            }

         //...
        }

Its a problem with case-insensitive query because it always return the first match:

[2024-05-03 09:05:37] local.INFO: array (
0 => 'Scan: craftable-pro/First name',
1 => 'New trans: craftable-pro/First name',
)
[2024-05-03 09:05:37] local.INFO: array (
0 => 'Scan: craftable-pro/First name',
1 => 'Found key: First name',
2 => 'Confirm match',
)
[2024-05-03 09:05:37] local.INFO: array (
0 => 'Scan: craftable-pro/First name',
1 => 'Found key: First name',
2 => 'Confirm match',
)
[2024-05-03 09:05:37] local.INFO: array (
0 => 'Scan: craftable-pro/First Name',
1 => 'Found key: First name',
2 => 'New trans: craftable-pro/First Name',
)
[2024-05-03 09:05:37] local.INFO: array (
0 => 'Scan: craftable-pro/First Name',
1 => 'Found key: First name',
2 => 'New trans: craftable-pro/First Name',
)
[2024-05-03 09:05:37] local.INFO: array (
0 => 'Scan: craftable-pro/First name',
1 => 'Found key: First name',
2 => 'Confirm match',
)
[2024-05-03 09:05:37] local.INFO: array (
0 => 'Scan: craftable-pro/First name',
1 => 'Found key: First name',
2 => 'Confirm match',
)
[2024-05-03 09:05:37] local.INFO: array (
0 => 'Scan: craftable-pro/First name',
1 => 'Found key: First name',
2 => 'Confirm match',
)
[2024-05-03 09:05:38] local.INFO: array (
0 => 'Scan: craftable-pro/First Name',
1 => 'Found key: First name',
2 => 'New trans: craftable-pro/First Name',
)
[2024-05-03 09:05:38] local.INFO: array (
0 => 'Scan: craftable-pro/First Name',
1 => 'Found key: First name',
2 => 'New trans: craftable-pro/First Name',
)

@roolian
Copy link
Author

roolian commented May 3, 2024

Solution

Case sensitive can be set on column (for mysql) in the migration:

Schema::create('language_lines', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('group')->index();
            $table->text('key')->collation('latin7_general_cs');
            $table->json('text');
            $table->timestamps();
            $table->softDeletes();
        });

So in vendor/brackets/craftable-pro/src/Translations/Repositories/LanguageLineRepository.php

// because Laravel & MySQL are case-insensitive by default, let's double check we have the right $languageLine
        if ($languageLine && $languageLine->key === $key) {
  • If collation is case insensitive, this test is buggy because the query always return the same match.
  • if collation is case sensitive, this test is useless because query will find the good match

Now i go back to my project 😄

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