Skip to content

feat: declare the text parameters of the attributes in resources/i18n.php - #15

Merged
ogorzalka merged 1 commit into
mainfrom
feat/i18n-declaration
Nov 10, 2026
Merged

ogorzalka merged 1 commit into
mainfrom
feat/i18n-declaration

Conversation

@ogorzalka

Copy link
Copy Markdown
Member

What

A data file, resources/i18n.php, lists the constructor parameters of the attributes that hold text shown to a person (labels, titles, descriptions, singular and plural names…), and composer.json announces it under extra.pollora.i18n.

return [
    PostType::class => ['singular', 'plural'],
    AdminCol::class => ['title'],
    // …
];

It is plain data: this package does not depend on any translation package, and a tool such as pollora/i18n can read the file to know which strings to extract and translate.

Drift guard

tests/Unit/I18nDeclarationTest.php walks every attribute class of src/ (file system and reflection, no hard-coded list) and requires each string or array constructor parameter to be either in resources/i18n.php or in an explicit "technical" list of the test (slugs, keys, hooks, capabilities, formats, callbacks…). A parameter that is in neither makes the test fail and says what to do, so a new text parameter cannot be added without deciding whether it is translated. It also checks that no parameter is classified twice, that no entry points at a parameter that no longer exists, that composer.json declares the file, and that .gitattributes does not exclude resources/.

Choices worth a look

  • Translatable: Ability::label and description, Meta::label, description and group, PostType\FeaturedImage::value, Role::label.
  • Not translatable: the array parameters that mix text and technical values (AdminCols, AdminFilters, Template, Meta::hints): the text inside them is marked where it is written, with new Translatable('…') from pollora/i18n, rather than declared here. Taxonomy\DefaultTerm (stored in the database at creation) and WpCli\Synopsis (WP-CLI does not translate them).

No dependency is added and no signature changes.

….php

A translation tool reads the file as data, found through extra.pollora.i18n in
composer.json. A test fails when an attribute gains a text parameter that is
classed neither as translatable nor as technical.
@ogorzalka
ogorzalka merged commit 4f0fb6a into main Nov 10, 2026
15 checks passed
@ogorzalka
ogorzalka deleted the feat/i18n-declaration branch November 10, 2026 14:57
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.

1 participant