Skip to content

Conversation

@afbora
Copy link
Member

@afbora afbora commented Jan 26, 2024

This PR …

This was a more complex problem than I expected (always πŸ™ˆ). Because the system should be able to read, update and delete language variables both from the language file and from a custom root. It involves a breakage change, but I wanted to remove the code complexity by creating a separate LanguageVariables object.

Todos/To discuss

  • Inconsistencies: Sometimes we call them variables, sometimes translations (e.g. in the k-language-view and the API endpoints). Do we fully want to switch to variables? Then we should make the changes everywhere (with legacy fallbacks for now).
  • Do we need to pass $props['translation'] to the LanguageVariables object? Or would it be better to keep them separate, so that LanguageVariables only takes care about the file and its value. And Language has the job to merge both arrays ($props['translation']) and $this->variables->toArray()) together. As well as filtering all keys from $props['translation'] to only write everything remaining to the variables file.
  • Update @since tags
  • Add unit tests for new/altered code
  • Passing unit tests

Changelog

Fixes

Features

  • New language:variables root
$kirby = new Kirby([
    'roots' => [
        'language:variables' => __DIR__ . '/site/variables'
    ]
]);

Breaking changes

  • Language::translations() deprecated, use Language::variables() instead
  • $language->translations() returns LanguageVariables object instead array. Use $language->translations()->toArray() or $language->variables()->toArray().

Ready?

  • Unit tests for fixed bug/feature
  • In-code documentation (wherever needed)
  • Tests and checks all pass

For review team

@afbora afbora added needs: discussion πŸ—£ Requires further discussion to proceed type: enhancement ✨ needs: tests πŸ§ͺ Requires missing tests labels Jan 26, 2024
@afbora afbora requested a review from a team January 26, 2024 14:07
@afbora afbora self-assigned this Jan 26, 2024
Copy link
Member

@lukasbestle lukasbestle left a comment

Choose a reason for hiding this comment

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

Great solution to move the logic to a separate class. πŸ‘
A few things I noticed while skimming through the changes:

@lukasbestle lukasbestle removed the needs: discussion πŸ—£ Requires further discussion to proceed label Jan 27, 2024
@afbora afbora mentioned this pull request Jan 27, 2024
5 tasks
@tobimori
Copy link
Contributor

tobimori commented Feb 6, 2024

Excited for this, thanks! Will this include the possibility to add translations (e.g. for the panel) even if the language does not have a content language assigned to it? Some of my pages are German only, but should still have English translations for the panel.

@afbora
Copy link
Member Author

afbora commented Feb 10, 2024

@tobimori In your case; multilingual is not enabled for the frontend, but you want to add translations (for example for blueprint labels) for users in different languages using the panel. Do I understand correctly?

@tobimori
Copy link
Contributor

tobimori commented Feb 10, 2024

@tobimori In your case; multilingual is not enabled for the frontend, but you want to add translations (for example for blueprint labels) for users in different languages using the panel. Do I understand correctly?

Multilingual is enabled, but the languages in the panel might differ from the languages in the frontend.
Let's say I have de and en in the frontend, but I want to add a french translation for my field labels etc. as well.

Currently, I have a translations directory and load yaml files from a plugin. (https://github.com/tobimori/kirby-baukasten/blob/main/site/plugins/project-extended/index.php#L20)

@afbora
Copy link
Member Author

afbora commented Feb 10, 2024

If there is no FR language (so fr.php language file), unfortunately it will not load custom FR translations. It will only load the translation files for existing languages from a custom root.

@tobimori
Copy link
Contributor

😦

@afbora afbora added this to the 5.0.0 milestone Mar 29, 2024
@distantnative distantnative force-pushed the lab/afbora/new-translations-root branch from 7f4acb1 to 178fa70 Compare July 22, 2024 15:33
Copy link
Member

@distantnative distantnative left a comment

Choose a reason for hiding this comment

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

Some first comments. Let me know if you think I misunderstood parts of the code :)

@afbora afbora changed the title [v5] New translations root New translations root Sep 1, 2024
@afbora afbora force-pushed the lab/afbora/new-translations-root branch 7 times, most recently from a18e0ef to b1b372f Compare September 13, 2024 20:35
@afbora
Copy link
Member Author

afbora commented Sep 13, 2024

@distantnative I did some changes based on your reviews and done some improvements. Would be nice if you take a look when you're available before writing unit tests and last touch πŸ™Œ

@afbora afbora changed the title New translations root New language:variables root Sep 16, 2024
@afbora afbora force-pushed the lab/afbora/new-translations-root branch from b56dad6 to e4d97b1 Compare December 9, 2024 12:10
@afbora afbora modified the milestones: 5.0.0, 5.1.0 Feb 10, 2025
@distantnative distantnative changed the base branch from v5/develop to develop-minor June 24, 2025 21:14
@distantnative distantnative force-pushed the lab/afbora/new-translations-root branch from 854ddb5 to 1cea8dd Compare August 7, 2025 15:30
@distantnative distantnative force-pushed the lab/afbora/new-translations-root branch from 1cea8dd to 05c2e0f Compare August 7, 2025 15:32
@distantnative distantnative changed the base branch from develop-minor to v6/develop August 7, 2025 15:32
@distantnative
Copy link
Member

Rebased this but moved it to v6 due to the breaking change.

@distantnative distantnative modified the milestones: 5.1.0, 6.0.0 Aug 7, 2025
@distantnative distantnative added the needs: discussion πŸ—£ Requires further discussion to proceed label Aug 7, 2025
@distantnative distantnative changed the title New language:variables root feat: language:variables root Aug 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs: discussion πŸ—£ Requires further discussion to proceed needs: tests πŸ§ͺ Requires missing tests

Development

Successfully merging this pull request may close these issues.

External language variables setup no longer works since K4's language views

6 participants