Skip to content

[6.x] Forms 2: Follow localization conventions - #16004

Open
duncanmcclean wants to merge 3 commits into
6.xfrom
forms-localization-conventions
Open

duncanmcclean wants to merge 3 commits into
6.xfrom
forms-localization-conventions

Conversation

@duncanmcclean

@duncanmcclean duncanmcclean commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

This pull request updates Forms 2 strings to follow our localization conventions.

  • Sentences used as their own translation keys have been moved into lang/en/messages.php.
  • Form fieldtype descriptions now live in lang/en/form-fieldtypes.php under <handle>.description, resolved the same way as titles. Fieldtypes with a $description property, like addon fieldtypes, work as before.
  • Form fieldtype examples (labels, placeholders, options and values) are now translatable, under <handle>.example.* in lang/en/form-fieldtypes.php. Previously, they weren't picked up by translator generate.
  • Strings that were split into fragments are now single strings with placeholders, so translators can reorder them:
    • "Drag fields here to build your form or :link"
    • ":metric of users checked the toggle"
    • The builder's field count, which now uses __n with the count inside the string.
  • Sample values used in previews are now translatable, including the email, URL, phone and postcode samples in the Text fieldtype, the Lorem ipsum sentence/paragraph, and the List and Link fieldtypes' preview values.
  • Removed the unused form_builder key and a duplicate field_conditions_reserve_space_when_hidden_instructions key.

Amp thread: https://ampcode.com/threads/T-f5d22e52-fd5f-4032-b21e-06a349df56f3

Base automatically changed from forms-2 to 6.x November 24, 2026 17:49
Co-authored-by: Duncan McClean <duncan@duncanmcclean.com>
@jasonvarga
jasonvarga force-pushed the forms-localization-conventions branch from 5945f16 to def8a17 Compare November 24, 2026 20:18
@helloDanuk

Copy link
Copy Markdown
Contributor

Thanks for making the sample values in Text::previewValue() translatable! Two things I noticed while translating Forms 2 into German in #16029.

1. Some sample values are still hard-coded

In Text::previewValue():

'email' => 'name@example.com',
'url' => 'https://example.com',
'phone' => '555-0100',
'postcode' => '97477',

Once names and addresses are localized, the email connection preview mixes countries. Written as a Swiss address, for example:

Anna Muster, Bahnhofstrasse 1, 97477 Bern, BE, Schweiz, 555-0100

97477 is a US postcode and 555-0100 a US test number. Swiss postcodes have four digits, German ones five, and phone formats differ too. Email and URL matter less, but a local part matching the localized name (e.g. anna.muster@example.com) would fit better.

The same goes for the other sample values: SampleValue::sentence() and paragraph() (Lorem ipsum), Lists::previewValue() (['Lorem', 'Ipsum', 'Dolor']) and Link::previewValue() (https://example.com).

Could all of these be wrapped in __() as well? Translators who are happy with Lorem ipsum or example.com can keep them as they are, and others can use local formats.

2. The fieldtype examples in the form builder can't be translated yet

The description says example() content is unchanged since it's translated by Vue when rendered. The labels do go through __() in Publish/Field.vue, but the strings live in plain PHP arrays, so translator generate never picks them up. Translators can't add them, and generate drops them if they do. In a German CP, the examples show "Your Name", "Pick your favorite season", "Agreement" and so on. Only "Email Address" and "Phone Number" appear translated, because those keys happen to exist elsewhere.

The values can't be translated either: "Jamie Schmidt", jamie@schmidt.family, "I can whistle with crackers in my mouth", "A raccoon stole my keys", the song titles in the Dropdown example, "Pepperoni", the seasons, etc. The Currency example uses USD, which a translation could swap for another valid currency code like CHF or EUR.

Wrapping the labels, options and values in example() in __() would fix both, e.g.:

'display' => __('Your Name'),
// ...
'value' => __('Jamie Schmidt'),

The playful examples are a nice touch, and translators could then adapt them to their language rather than translate them literally.

ampagent and others added 2 commits November 27, 2026 10:47
email, url, phone and postcode samples use `messages.sample_value_*` keys since the translator would treat dotted strings like `name@example.com` as keys.

Amp-Thread-ID: https://ampcode.com/threads/T-6755f1f3-3769-4eaf-9345-5bed4eb0bc04
Co-authored-by: Duncan McClean <duncan@duncanmcclean.com>
Amp-Thread-ID: https://ampcode.com/threads/T-6755f1f3-3769-4eaf-9345-5bed4eb0bc04
Co-authored-by: Duncan McClean <duncan@duncanmcclean.com>

Copy link
Copy Markdown
Member Author

Thanks @helloDanuk, good catches! I've pushed changes for both:

  • The remaining sample values (email, URL, phone, postcode, Lorem ipsum, and the List & Link previews) are now translatable. The email, URL, phone and postcode samples live under messages.sample_value_*, since translator generate would otherwise treat dotted strings like name@example.com as keys.
  • The form fieldtype examples are now translatable too, under <handle>.example.* in form-fieldtypes.php. That covers labels, placeholders, option labels and text values, so feel free to adapt them rather than translating them literally. The currency code in the Currency example is still hard-coded.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants