bnomei
January 19, 2019, 6:42pm
1
i am trying to make make a custom property translatable using the blueprint. so i am not looking for a solution to static translate a property.
opened 01:34PM - 09 Jan 19 UTC
closed 03:04PM - 21 Jan 19 UTC
enhancement
For multi language setups a translatable `label` and `progress` strings would be⌠a great addition for smooth overall user experience. đ
current
janitor:
type: janitor
label: Clean Cache
progress: Cleaning Cache...
job: clean
expected
janitor:
type: janitor
label:
en: Clean Cache
de: Cache leeren
progress: Cleaning Cache...
job: clean
like in blueprints:Translating blueprints | Kirby CMS
thought i would find something in the docs how to do that for plugins but could not. how to achieve that?
It is right there: https://getkirby.com/docs/reference/extensions/fields#php-definition
Subheadline âTranslated valuesâ. You would need to process it like this in your field props PHP definition.
bnomei
January 19, 2019, 7:22pm
3
'label' => function (string $label = null) {
return \Kirby\Toolkit\I18n::translate($label);
},
yield error
Invalid value for âlabelâ
not other debug data in browser console available.
i am using devkit 3.0.0 single-language setup. only user account switched from en to de language in its index.php.
bnomei
January 19, 2019, 7:35pm
4
did a print_r/is_null of return value using kirbylog plugin and its null.
bnomei
January 21, 2019, 9:03am
5
sorry to pull you into this thread but maybe apart from @distantnative panel plugin master @sylvainjule knows whats wrong. is my plugin broken or does it simply not work as intended.
1 Like
You should get it working with:
'label' => function ($label = null) {
return \Kirby\Toolkit\I18n::translate($label, $label);
},
You shouldnât expect $label to be a string if itâs a translatable object.
Note the second $label arg in the translate function, used as a fallback when the field isnât translatable (ie. is a simple string)
2 Likes
bnomei
January 21, 2019, 11:12am
7
@sylvainjule thank you. i should have checked the code for the translate function.