Skip to content

[Translation] [Bridge][Lokalise] Fix empty keys array in PUT, DELETE requests causing Lokalise API error #58983

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

Conversation

DominicLuidold
Copy link
Contributor

Q A
Branch? 5.4
Bug fix? yes
New feature? no
Deprecations? no
Issues /
License MIT

This PR fixes two cases where an empty keys array is passed to a PUT/DELETE request, resulting in a Lokalise API error.

The empty arrays are the result of a Symfony\Component\Translation\TranslatorBag containing one or more Symfony\Component\Translation\MessageCatalogue without any messages getting passed into the Symfony\Component\Translation\Bridge\Lokalise\LokaliseProvider (which is expected behaviour, see here and below).

This is the case if either

  • bin/console translation:push lokalise
  • bin/console translation:push lokalise --delete-missing

is called when both the local translations as well as the translations on Lokalise match 1:1 for a given translation domain.

This will fix the following erros that might be observed while running the mentioned commands:

Before/after for translation:push lokalise

Before:

$ bin/console translation:push lokalise --domains=validators

ERROR     [app] Unable to get keys ids from Lokalise: "{"error":{"message":"`filter_filenames` parameter has invalid values","code":400}}".

                                                                                                                     
 [OK] All local translations has been sent to "lokalise" (for "de, en, fr, it" locale(s), and "validators"           
      domain(s)).

After:

$ bin/console translation:push lokalise --domains=validators

                                                                                                                     
 [OK] All local translations has been sent to "lokalise" (for "de, en, fr, it" locale(s), and "validators"           
      domain(s)).
Before/after for translation:push lokalise --delete-missing

Before:

$ bin/console translation:push lokalise --domains=validators --delete-missing

In LokaliseProvider.php line 135:
                                                                                                            
  Unable to delete keys from Lokalise: "{"error":{"message":"`keys` parameter is not valid","code":400}}".  
                                                                                                            

translation:push [--force] [--delete-missing] [--domains [DOMAINS]] [--locales [LOCALES]] [--] [<provider>]

After:

$ bin/console translation:push lokalise --domains=validators --delete-missing

                                                                                                                     
 [OK] Missing translations on "lokalise" has been deleted (for "de, en, fr, it" locale(s), and "validators"           
      domain(s)).

                                                                                                                     
 [OK] All local translations has been sent to "lokalise" (for "de, en, fr, it" locale(s), and "validators"           
      domain(s)).

@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has a contribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (see https://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (see https://symfony.com/releases)
  • Features and deprecations must be submitted against the 7.3 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@carsonbot carsonbot changed the title [Translation][Bridge][Lokalise] Fix empty keys array in PUT, DELETE requests causing Lokalise API error [Translation] [Bridge][Lokalise] Fix empty keys array in PUT, DELETE requests causing Lokalise API error Nov 25, 2024
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

Nice thanks

@DominicLuidold
Copy link
Contributor Author

@nicolas-grekas Thanks for your review!

The failing tests seem unrelated. :)

@nicolas-grekas nicolas-grekas force-pushed the fix_translation-bridge-lokalise-empty-encoded-keys-array branch from 0c17119 to 2e51808 Compare November 25, 2024 15:59
@nicolas-grekas
Copy link
Member

Thank you @DominicLuidold.

@nicolas-grekas nicolas-grekas merged commit 294a39f into symfony:5.4 Nov 25, 2024
8 checks passed
@fabpot fabpot mentioned this pull request Nov 27, 2024
@DominicLuidold DominicLuidold deleted the fix_translation-bridge-lokalise-empty-encoded-keys-array branch November 27, 2024 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants