fix(editor): map XOOPS locale to TinyMCE 7 pack code (#76)#78
Conversation
The getLanguage() fallback emitted TinyMCE 3-style codes (strtolower + '-' + '_utf8', e.g. zh-tw_utf8) that match no TinyMCE 7 language pack, so non-English sites without _XOOPS_EDITOR_TINYMCE7_LANGUAGE silently fell back to English. - Add XoopsFormTinymce7::normalizeLanguageCode(): strips the legacy _utf8 suffix, maps known XOOPS codes to TinyMCE 7 pack filenames (fr -> fr_FR, sv -> sv_SE, zh-tw -> zh_TW, ...), and otherwise normalises to <lang>_<REGION>; empty -> 'en'. - getLanguage() fallback uses it; explicit-constant path unchanged. - Correct the stale TinyMCE 3 comment in the english/french editor language files (dead moxiecode URL) and set french to the valid TinyMCE 7 pack name 'fr_FR'. - Data-provider unit tests cover the documented contract. Closes XOOPS#76.
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughThis PR refactors TinyMCE 7 language-code fallback handling in XOOPS Core 2.7.0 to emit locale pack filename codes ( ChangesLanguage Code Normalization
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #78 +/- ##
============================================
- Coverage 18.13% 18.12% -0.02%
Complexity 7854 7854
============================================
Files 666 666
Lines 43208 43240 +32
============================================
Hits 7837 7837
- Misses 35371 35403 +32 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@htdocs/class/xoopseditor/tinymce7/formtinymce.php`:
- Around line 189-199: This helper currently splits $key into $parts and returns
pack codes even for malformed tokens; update the fallback-normalization logic
that works on $key/$parts to validate tokens strictly: ensure $parts[0] matches
a two-letter lowercase language code and, if $parts[1] exists, ensure it matches
a two-letter alphabetic region code before returning $parts[0] or $parts[0] .
'_' . strtoupper($parts[1]); if validation fails at any point return 'en'. Use
the existing $key and $parts variables and preserve the existing uppercase
conversion for the region.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 03902892-bc57-46c9-9a80-d58fcbb385d9
📒 Files selected for processing (5)
docs/changelog.270.txthtdocs/class/xoopseditor/tinymce7/formtinymce.phphtdocs/class/xoopseditor/tinymce7/language/english.phphtdocs/class/xoopseditor/tinymce7/language/french.phptests/unit/htdocs/class/xoopseditor/tinymce7/XoopsFormTinymce7Test.php
There was a problem hiding this comment.
Pull request overview
This PR updates the TinyMCE 7 editor adapter so XOOPS fallback locale codes resolve to TinyMCE 7 language-pack filenames instead of legacy TinyMCE 3-style codes.
Changes:
- Adds locale normalization and mapping for TinyMCE 7 language codes.
- Updates English/French editor language metadata and French pack code.
- Adds unit coverage for representative fallback normalization cases and documents the fix in the 2.7.0 changelog.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
htdocs/class/xoopseditor/tinymce7/formtinymce.php |
Adds TinyMCE 7 language-code mapping and fallback normalization. |
htdocs/class/xoopseditor/tinymce7/language/english.php |
Updates the language-pack comment. |
htdocs/class/xoopseditor/tinymce7/language/french.php |
Updates the language-pack comment and changes French to fr_FR. |
tests/unit/htdocs/class/xoopseditor/tinymce7/XoopsFormTinymce7Test.php |
Adds data-provider tests for fallback locale normalization. |
docs/changelog.270.txt |
Records the TinyMCE 7 fallback language handling fix. |
| if (!isset($parts[1]) || $parts[1] === '') { | ||
| return $parts[0]; | ||
| } | ||
|
|
||
| return $parts[0] . '_' . strtoupper($parts[1]); |
| public function normalizeForTest(string $langcode): string | ||
| { | ||
| return self::normalizeLanguageCode($langcode); | ||
| } | ||
| }; | ||
|
|
||
| self::assertSame($expected, $editor->normalizeForTest($langcode)); |
…S#78 review) - CodeRabbit (blocking, valid): normalizeLanguageCode() could turn a malformed _LANGCODE into a junk pack code. Validate the split tokens (language ^[a-z]{2,3}$, region ^[a-z]{2}$); anything else degrades to the built-in 'en'. Contract preserved (mapped/empty cases bypass it; es-mx -> es_MX still works). - Copilot (valid): de_DE/es_ES (and it/ja/nl/pl/ru/tr/uk/vi country variants) fell through to non-existent pack names. Add explicit map aliases that collapse them to the bare TinyMCE 7 pack. Done via the map (not a generic collapse) so a real regional pack like es_MX is intentionally NOT collapsed and still resolves. - Copilot (valid coverage gap): add a separate-process end-to-end test proving getLanguage() runs _LANGCODE through the normalizer when _XOOPS_EDITOR_TINYMCE7_LANGUAGE is absent; plus data-provider cases for de_DE, es_ES, malformed and bad-region inputs. Not contorting for Sonar S1142 (too-many-returns): the gate passes and guard clauses are clearer here than a forced single-exit. Constant S115 is a XOOPS language-constant-convention false positive (do not rename).
|



Closes #76.
Problem
XoopsFormTinymce7::getLanguage()'s fallback (no_XOOPS_EDITOR_TINYMCE7_LANGUAGEdefined) produced TinyMCE 3-style codes —str_replace('_','-', strtolower(_LANGCODE))+ a_utf8suffix (e.g.zh-tw_utf8, and evenen→en_utf8). TinyMCE 7 packs are<lang>or<lang>_<REGION>(fr_FR.js,zh_TW.js, …) with no_utf8, so every non-English site without the constant silently fell back to English. #72 fixed only the explicit-constant path; this is the fallback.Fix
normalizeLanguageCode()(pure, static): trims, strips the legacy_utf8, maps known XOOPS codes to the canonical TinyMCE 7 pack name (fr→fr_FR,sv→sv_SE,zh-tw/zh_TW/zh-hk→zh_TW,pt-br→pt_BR, …), otherwise normalises to<lang>_<REGION>; bare languages whose TinyMCE pack is already bare (de,ru,it, …) pass through; empty/invalid →en. Unknown codes degrade to TinyMCE's English default (never worse than today).getLanguage()fallback uses it; the explicit-constant path is unchanged (fix: preserve TinyMCE 7 language locale casing #72 semantics preserved).jscripts/langspath) in the english & french editor language files; set french to the validfr_FRpack name.No new language
define()(only a comment + value change) → nolang_diff.txtentry required.Tests
Data-provider unit tests in
XoopsFormTinymce7Testassert the documented contract (en→en,fr→fr_FR,zh_TW/zh-tw/zh-tw_utf8→zh_TW,pt_BR→pt_BR,sv→sv_SE,es-mx→es_MX,''→en). These are real executable unit tests of a pure method (not static-source) — they also give genuine patch coverage.Verification: lint clean on all 5 files; every data-provider case + extra robustness probes (trimming,
depassthrough,zh-HK,en-US) verified deterministically against the implementation locally. I could not run the PHPUnit suite in this environment — CI is the final word.Note
The bundled TinyMCE 7 still ships no language packs (
js/tinymce/langs/is just a README). This fix makes the editor request the correct pack code; sites must still add the desired<code>.jspack for a non-English UI. That packaging decision is out of scope here.Test plan
_LANGCODEis e.g.fr/zh-TWwith no editor-language constant, confirm TinyMCE requestsfr_FR/zh_TWSummary by CodeRabbit