📝 docs(api): document the CLDR plural rules on the v3 languages endpoint - #4801
Open
mauretto78 wants to merge 1 commit into
Open
📝 docs(api): document the CLDR plural rules on the v3 languages endpoint#4801mauretto78 wants to merge 1 commit into
mauretto78 wants to merge 1 commit into
Conversation
/api/v3/languages returns a fourth field per language, plurals, carrying the CLDR plural rules that the plural and selectordinal arguments of an ICU message select on. The spec described only code, name and direction, and carried no example response at all, so Swagger UI synthesised a placeholder out of the schema. Reword the endpoint summary and description, attach the real payload for ar-SA and it-IT as the 200 example, add the plurals property to the Language definition, and describe the rule set with the new LanguagePluralRules and PluralCategoryRule definitions. Both example entries were compared key for key against what the matecat/icu-intl resources produce, so the documented example cannot drift from the payload unnoticed.
🧪 Test-Guard Report✅ PASS — All changed source files have adequate test coverage. Coverage Analysis: ⏭️ SKIPNo source files to analyze — all changed files are tests or excluded. Test File Matching: ✅ PASSNo source files to check Per-File Evaluation: ✅ PASSNo source files to evaluate. Result: ✅ PASS |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
GET /api/v3/languagesreturns a fourth field per language,plurals, carrying the CLDRplural rules that the
pluralandselectordinalarguments of an ICU message select on. Thespec described only
code,nameanddirection, and carried no example response at all — soSwagger UI synthesised a
{"code": "string", …}placeholder out of the schema.This documents the field, replaces that placeholder with the real payload, and rewords the
endpoint summary and description. Documentation only: no PHP, JS or SQL is touched.
Type
feat— new user-facing featurefix— bug fixrefactor— restructure without behavior changechore— build, deps, config, docsperf— performance improvementtest— test coverageChanges
public/api/swagger-source.json→paths./api/v3/languages.getsummaryanddescription;200gains anexamplesblock holding the real payload forar-SAandit-IT; response description re-cased fromLanguages Listto sentence casepublic/api/swagger-source.json→definitions.Languagepluralsproperty ($ref+x-nullable); per-fieldexamplevalues;codedescription corrected fromRfc codetoBCP 47 language+region codepublic/api/swagger-source.json→definitions.Languagesnamepublic/api/swagger-source.json→definitions.LanguagePluralRules(new)name,isoCode,cardinal,ordinal— the shape ofLanguageRulesFragmentpublic/api/swagger-source.json→definitions.PluralCategoryRule(new)category,rule,human_rule,example— the shape ofCategoryFragment, with thezero/one/two/few/many/otherenumTesting
vendor/bin/phpunit --exclude-group=ExternalServices --no-coveragepasses./vendor/bin/phpstanpasses (0 errors, with baseline)The spec was checked against the code that actually builds the response, not against the old
prose.
/api/v3/languagesis routed atlib/Routes/api_v3_routes.php:243toController\API\V2\SupportedLanguagesController::index, and the entry shape comes from thematecat/icu-intlpackage (Locales\Languages::buildEnabledLanguageList()plusinjectPluralRules(), serialised by theLanguageRulesFragmentandCategoryFragmentDTOs).Verification performed:
$refin it resolves — no dangling references, anddefinitions.Languagenow carries all four properties.vendor/matecat/icu-intl/src/resources/pluralRules.jsonandsupported_langs.jsonproducefor
ar-SAandit-IT, so the example cannot drift from the payload silently.ar-SAwas chosen because it is the only shape that exercises all six cardinal categoriesand an RTL
direction;it-ITadds a non-trivialmanycardinal and a two-category ordinal.No PHP or JS changed, so
phpunit,phpstanandyarn testare untouched by this PR and werenot re-run.
npx prettier --checkstill flagsswagger-source.json, but it flags the fileunmodified too (confirmed by stashing) — pre-existing, and
--writewould reformat all 230 KB.AI Disclosure
Claude Code (claude-opus-5)
Notes
Two facts about the payload are worth a reviewer's eye, because both are documented as they
really behave rather than as one might expect:
plurals.isoCodeis the base ISO code, so regional variants share one rule set(
en-US→en);pt_ptis currently the only rule set defined per region.plurals.namenames whichever variant the shared set was built from —en-USreports
plurals.name: "English (Australia)". TheLanguagePluralRules.namedescription saysso explicitly, and the examples deliberately use
it-ITandar-SA, where the two namescoincide, so the example itself does not look like a bug.
pluralsis typedLanguageRulesFragment|nullin the package, so it is markedx-nullable: trueeven though no currently enabled language resolves tonull.Out of scope, flagged for later: the identical payload is also served at
/api/v2/languagesand/api/app/languages(the route the React app actually calls), and neither appears in the spec.public/api/swagger-source.jsis a drifted, unread copy of the spec and was left alone.