daandelange/translatedlayout
Composer 安装命令:
composer require daandelange/translatedlayout
包简介
Layout and blocks fields with embedded translation logic.
README 文档
README
This plugin brings translation logics into the native layouts fields.
Experimental
While the kirby team is waiting for some heavy refactoring for recursively bringing translation logics into their "complex fields", this plugin aims to provide a temporary workaround for multi-language websites.
This is an experimental draft trying to bring some translation logic to blocks, columns and layouts. It turns out to be quite powerful already with just a minimal set of changes compared to the native field behaviour.
Current state :
Tested on a single configuration, works well but not extensively tested. Therefore, please note that there remains a risk of data loss. (Do not use without backups!)
There is no translatedblocks fields nor toTranslatedBlocks method (yet?), please use layouts instead.
Implementation
- The primary language (default) inherits the default
LayoutFieldbehaviour and remains (almost?) identical to the native Kirby Layout field. - The seconday languages (translations) of this field are always syncronized on parse (aka
$field->fill($value)).- Identical structures : The layouts and blocks structures are defined by the default language using their unique
id. - Fallback : If a block has no translation, it's replaced with the default language.
- Sanitation : If a block translation is not available in the default language, it's removed. All blocks from the default language are guaranteed to be available for translation in the panel.
- Panel GUI : Non-translateable fields and blocks are disabled, preventing panel users from changing the layout and adding blocks in translations.
- Data : The syncronized translation is saved as a blocks and columns array and parsed on retrieval. (this saves some disk space and makes data more readable).
- Identical structures : The layouts and blocks structures are defined by the default language using their unique
Requirements
-
Version
0.3.3-beta: Kirby 3.8 or above. -
(Kirby 4 compatibility should be easy to implement; mainly a few changed function signatures and namespace renames)
-
Version
1.0.0: Kirby 5 or above. -
Note: This plugin heavily relies on the use of the panel. If you'd like to manually edit a
translatedlayoutfield via the text content file, it's not recommended to use this plugin, as it's probably not recommended to use blocks without the panel. (Meanwhile, it still is possible, and this plugin even simplifies the translation files).
Installation
Choose one:
- Download: Download and copy this repository to
/site/plugins/translatedlayout. - Git submodule:
git submodule add https://github.com/daandelange/kirby-translatedlayout.git site/plugins/translatedlayout. - Composer:
composer require daandelange/translatedlayout.
Setup
Import existing data
- The default language saves as the native Kirby layouts field.
- Translations have a different content structure and only save the translated block fields.
Warning! If you already have a layout with translated content, switching to this field will erase all translations unless you manually give the same id to blocks/rows/columns in the translations data structure. There is no automatic script available.
The same happens when you change the default language so make sure it's correct, and to never change it again.
Blueprints
In your page blueprints, you can simply replace a type: layout field by type: translatedlayout. Read more about how to use the respective fields in the official Kirby docs.
The only difference is an extra translate property on fields, please refer to this example:
sections: content: type: fields fields: mylayout: label: Translated Layout Demo type: translatedlayout translate: true # <--- enables syncing of translations (layout field) layouts: - "1/1" - "1/2, 1/2" - "1/3, 1/3, 1/3" fieldsets: translateable: label: Fully Translateable Blocks type: group fieldsets: heading: extends: blocks/heading translate: true # same as default value - list - text partiallytranslateable: label: Blocks with some translateable fields type: group fieldsets: image: # over-rule the translated option of existing fields label: Image (non translateable src) type: image translate: false fields: link: translate: false url: # custom block example name: Url (non-translateable source) icon: cog fields: link: type: url translate: false required: true text: type: text translate: true nontranslateable: label: Non-translated blocks type: group fieldsets: line: extends: blocks/line translate: false # Completely disable whole block translations settings: # You can also translate layout settings fields: class: type: text width: 1/2 translate: false # Don't translate purpose: type: text translate: true # Translate myblock: label: Translated Blocks Demo type: translatedblocks fieldsets: heading: extends: blocks/heading translate: true # same as default value - text line: extends: blocks/line translate: false # Completely disable whole block translations
To use predefined translation settings for the default kirby blocks, you may use :
fields: content: type: translatedlayout extends: fields/translatedlayoutwithfieldsets
This can be useful for quickly setting up this plugin in a test environment.
Beware that this will add the fields to your fieldsets if they don't exist yet.
To setup your own fieldsets, prefer copy/pasting from translatedlayoutwithfieldsets.yml and adapt it to your needs.
Templates
Use $field->toTranslatedLayout() in your templates to fetch & render the field contents. Like the native LayoutField's toLayouts, a Kirby\Cms\Layouts object is returned. There is absolutely no difference as the plugin acts during the data parse state.
Options
There are no options available yet. Would you like to contribute some ?
Development
- A small hack to fix KirbyUp's alias
@KirbyPanelsub-includes : (more info)- osx:
cd /path/to/translatedLayout/ && ln -s "../../../../kirby/panel/src/mixins" ./src/mixins - linux: todo
- other: Create an alias/symlink pointing from
translatedlayout/src/mixinsto/kirby/panel/src/mixins.
- osx:
npm install: Install the required dependencies.npm run dev: Develop mode (listen/compile).npm run build: Compile for publishing.
Feature ideas
- Plugin options : Set rather to fill with (untranslated) default language, or leave the translateable blocks empty ? (on translation creation only).
- Write some test cases.
Similar Plugins
- Synced-Structure : Syncs structures across languages using UUIDs. Note: This method doesn't work with
LayoutsandBlocksfields because they use theFieldClassinstead of Kirby's field blueprints.
License
MIT - Free to use, free to improve !
However, for usage in commercial projects, please seriously consider to improve the plugin a little and contribute back the changes with a PR, or hire someone to do so.
For contribution suggestions, you can search for todo in the source code or refer to open issues.
Credits
daandelange/translatedlayout 适用场景与选型建议
daandelange/translatedlayout 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 15 次下载、GitHub Stars 达 17, 最近一次更新时间为 2025 年 04 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「kirby3」 「kirby-plugin」 「kirby-cms」 「kirby5」 「kirby-field-plugin」 「kirby-panel-plugin」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 daandelange/translatedlayout 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 daandelange/translatedlayout 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 daandelange/translatedlayout 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Kirby 5 field for hierarchical menus with drag & drop level indentation.
Show references to a page or file on the objects blueprint.
Courier offers a convenient and painless solution for creating emails tailored for your Kirby website.
Plausible integration for Kirby CMS
A image cropping field for kirby.
Kirby Admin Bar
统计信息
- 总下载量: 15
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 17
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-04-09
