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

Language snippet is not translated in user blueprint #4869

Closed
chrfickinger opened this issue Nov 28, 2022 · 18 comments
Closed

Language snippet is not translated in user blueprint #4869

chrfickinger opened this issue Nov 28, 2022 · 18 comments
Assignees
Labels
type: bug 🐛 Is a bug; fixes a bug
Milestone

Comments

@chrfickinger
Copy link

Description

A blueprint of a page allows to specify a language snippet for title, e.g.

title: my.translated.snippet

This behavior does not work for User blueprints. I have to put the translated stuff right away in the blueprint, like:

title:
    de: German string
    en: English string
@afbora
Copy link
Member

afbora commented Nov 28, 2022

I can't reproduce the issue. How do you define the my.translated.snippet string?

@afbora afbora added needs: information ❓ Requires more information to proceed needs: replication 🔬 Requires a sample to reproduce the issue labels Nov 28, 2022
@chrfickinger
Copy link
Author

Hi Ahment.
I could help myself.
Strings are defined correctly (e.g. site/languages/en.php), but it seems to be necessary to fill in both language files for it to work.

Example: If I have set english as panel language, german must be present as well, otherwise the snippet will not be translated.

@chrfickinger
Copy link
Author

i forgot to mention, english is the default language in my project and it is not set.
So, the solution is: Every snippet must be available at least in default language to work.

@afbora
Copy link
Member

afbora commented Dec 1, 2022

  • Default language is EN
  • Secondary language is DE
  • Related translation is defined in DE but not in EN

Is this correct?

@chrfickinger
Copy link
Author

chrfickinger commented Dec 1, 2022

Yes, correct.

But there is another strange behavior: I added the missing language snippet, but it's not translated into secondary language. Only default language is used, no matter which language is selected.

@afbora
Copy link
Member

afbora commented Dec 1, 2022

Weird! Could you post your translation snippet, please? And which Kirby version do you use?

@chrfickinger
Copy link
Author

Kirby 3.8.2

site/language/en.php

return [
    'code' => 'en',
    'default' => true,
    'direction' => 'ltr',
    'locale' => [
        'LC_ALL' => 'en_GB'
    ],
    'name' => 'English',
    'translations' => [
        'panel.user.admin.title' => 'Admin',
        'panel.user.admin.description' => 'All permissions',
        'panel.user.editor.title' => 'Editor',
        'panel.user.editor.description' => 'Restricted permissions'
    ],
    'url' => '/'
];

site/language/de.php

return [
    'code' => 'de',
    'default' => false,
    'direction' => 'ltr',
    'locale' => [
        'LC_ALL' => 'de_DE'
    ],
    'name' => 'Deutsch',
    'translations' => [
        'panel.user.admin.title' => 'Administrator',
        'panel.user.admin.description' => 'Alle Berechtigungen',
        'panel.user.editor.title' => 'Redakteur',
        'panel.user.editor.description' => 'Eingeschränkte Berechtigungen'
    ],
    'url' => 'de'
];

@afbora
Copy link
Member

afbora commented Dec 7, 2022

@chrfickinger Sorry for late! I've tested with your setup.

"EN language is the default and a string has a translation in EN but no translation in DE, the translation should look for it in EN as fallback. But instead of fallback it looks like panel.user.editor.title."

Here is the issue and the behavior you expect, do I understand correctly?

* Also this is exists for page blueprints not only for user blueprints.

@afbora
Copy link
Member

afbora commented Dec 7, 2022

This is because we send the same string as fallback:
https://github.com/getkirby/kirby/blob/3.8.3/src/Cms/Blueprint.php#L321

And the $fallback argument data is returned before the fallback languages translation check:
https://github.com/getkirby/kirby/blob/3.8.3/src/Toolkit/I18n.php#L167-L180

@afbora afbora added needs: discussion 🗣 Requires further discussion to proceed and removed needs: information ❓ Requires more information to proceed needs: replication 🔬 Requires a sample to reproduce the issue labels Dec 7, 2022
@afbora
Copy link
Member

afbora commented Dec 8, 2022

@getkirby/kirby-staff Need your thoughts. Is this an issue can be fixed?

@distantnative
Copy link
Member

I'm getting quite headaches trying to debug the i18n class in that regard. Since this gets touched with the blueprint work anyways, we might have to wait for this first as I don't see an easy solution right now.

@distantnative
Copy link
Member

@chrfickinger
Coming back to this, I still don't quite find why this would be different for user blueprints. Is it really just a problem for user blueprints or general?

And could you please try if

title:
  *: my.translated.snippet

works instead?

@distantnative distantnative added needs: information ❓ Requires more information to proceed and removed needs: discussion 🗣 Requires further discussion to proceed labels Feb 25, 2023
@distantnative distantnative self-assigned this Feb 25, 2023
@distantnative
Copy link
Member

Nevermind, I think * would be the same here. I have an idea for the solution, but ig question mark if this won't have side effects.

@distantnative distantnative linked a pull request Feb 25, 2023 that will close this issue
5 tasks
@distantnative distantnative added type: bug 🐛 Is a bug; fixes a bug and removed needs: information ❓ Requires more information to proceed labels Feb 26, 2023
@bastianallgeier
Copy link
Member

@afbora afbora added this to the 3.9.3 milestone Mar 7, 2023
@afbora afbora removed a link to a pull request Mar 7, 2023
5 tasks
@afbora afbora linked a pull request Mar 7, 2023 that will close this issue
3 tasks
@lukasbestle
Copy link
Member

@chrfickinger For your information: We had to revert the fix for now because there was a regression: #5086
We will try our best to find a more robust fix for one of the next releases.

@chrfickinger
Copy link
Author

No worries. Thank you for letting me know

@distantnative distantnative reopened this Mar 8, 2023
@afbora afbora removed this from the 3.9.3 milestone Mar 21, 2023
@distantnative distantnative added this to the 4.0.0 milestone Mar 25, 2023
@distantnative
Copy link
Member

A fix has been merged into v4 branch. Will keep this open for now until we double check in the beta this has been solved.

@distantnative
Copy link
Member

Will be solved in v4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug 🐛 Is a bug; fixes a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants