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

Searching fails on translations #277

Closed
S8nsick66 opened this issue Feb 1, 2022 · 5 comments
Closed

Searching fails on translations #277

S8nsick66 opened this issue Feb 1, 2022 · 5 comments
Assignees
Labels

Comments

@S8nsick66
Copy link

I have Wordpress in Swedish.
The log shows things like "Misslyckades att logga in med användarnamnet ...." but searches for "misslyckades" give no results.
Searching for "failed" finds those items though.

@bonny bonny added the bug label Feb 2, 2022
@bonny bonny added this to To do in Simple History kanban Feb 2, 2022
@bonny
Copy link
Owner

bonny commented Mar 25, 2024

The message stored is

Failed to login with username "{login}" (incorrect password entered)

while the message shown is dependent of the current language, so for Swedish it will be

Misslyckades att logga in med användarnamnet ”” (felaktigt lösenord angavs)

So when searching for "misslyckades" that word does not exist in the db.

Solution:

  • When searching
    • Get all translations for domain simple-history: $translations = get_translations_for_domain( 'simple-history' );
    • For each translation
      • check if "misslyckades" matches anything inside the key "translations"
      • if it matches then add the singular version of the translation as the search query

Example of contents in $translations:

[Failed to login with username "{login}" (incorrect password entered)] => Translation_Entry Object
    (
        [is_plural] => 
        [context] => 
        [singular] => Failed to login with username "{login}" (incorrect password entered)
        [plural] => 
        [translations] => Array
            (
                [0] => Misslyckades att logga in med användarnamnet ”{login}” (felaktigt lösenord angavs)
            )

        [translator_comments] => 
        [extracted_comments] => 
        [references] => Array
            (
            )

        [flags] => Array
            (
            )

    )

@bonny
Copy link
Owner

bonny commented Mar 25, 2024

No, better method:


- Get a list of all loggers that a user has access to: `$loggers_user_can_read = $this->simple_history->get_loggers_that_user_can_read();`
- For each logger
  - Check all messages
    - If translated_text contains the word searched for
    - get the message_key for the found message, i.e. `user_login_failed`
    - include the message_key in the search
      - replace the search to only contain that message key?

Should work, but needs some testing. It will not be perfect. But search never is 🤷 
.

@bonny bonny moved this from To do to In progress in Simple History kanban Mar 25, 2024
@bonny bonny self-assigned this Mar 25, 2024
@bonny
Copy link
Owner

bonny commented Apr 2, 2024

Progress! LGTM 🤷

Before this change
search before

After this change
search after

@S8nsick66
Copy link
Author

Looking wonderful! Great job :)

@bonny bonny closed this as completed Apr 5, 2024
Simple History kanban automation moved this from In progress to Done Apr 5, 2024
@bonny
Copy link
Owner

bonny commented Apr 8, 2024

Hopefully fixed in version 4.14.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants