Skip to content

[3.0] Look language strings up under the name they are stored with - #9397

Open
albertlast wants to merge 1 commit into
SimpleMachines:release-3.0from
albertlast:3.0/lang-file-names
Open

[3.0] Look language strings up under the name they are stored with#9397
albertlast wants to merge 1 commit into
SimpleMachines:release-3.0from
albertlast:3.0/lang-file-names

Conversation

@albertlast

Copy link
Copy Markdown
Collaborator

Description

Lang::getTxt() takes a file: argument naming the language file a string lives in. It loads that file, then looks the key up in the flat Lang::$txt array, and returns '' when it is not there.

Nine calls name a file that does not define the key they ask for. I found them by sweeping every getTxt('key', …, file: 'Name') call against what Languages/en_US/*.php actually defines.

Where the right file happens to be loaded by something else on the same page, the lookup survives by luck. Where it is not, the string comes back empty. Two of these are certainly empty:

  • Sources/Parsers/MarkdownParser.php asked for quote_expand. That is the admin setting label "Minimum quote height to add an expand link on large quotes", and it lives in Admin, not General. The label wanted is code_expand. The value is substituted into data-expand-txt, and attachBbCodeEvents() in script.js only builds the button when that attribute has a value — so a fenced code block in Markdown never got its Expand button.
  • Sources/Actions/Profile/ThemeOptions.php asked for file: 'THemes', with a capital H. On a case sensitive filesystem no file is loaded at all.

The rest name a real file that simply does not hold the string:

Call site Key Named Actually in
Actions/Admin/Themes.php theme_opt_variant Themes Profile
Actions/Admin/Themes.php theme_opt_colormode Themes Profile
Actions/Login2.php (×2) invalid_credentials Login General
Actions/Search.php error_string_too_long Errors Search
Maintenance/Tools/Upgrade.php token_verify_fail Maintenance Errors
Themes/default/ManageLanguages.template.php edit_history_countedit_language_entries_add Admin ManageSettings
Themes/default/Register.template.php (×2) edit_history_count Agreement General

The two theme option headings are worth pointing out: the same two strings are fetched in Actions/Profile/ThemeOptions.php, and those calls already say file: 'Profile'. The admin side just disagrees with the profile side.

What I checked, and what I did not
  • The edit_language_entries_add button does render today ("Add another item" on Admin → Languages → Edit → Modifications), because the admin area loads ManageSettings for its own reasons. It is still naming the wrong file — it works by accident.
  • invalid_credentials, edit_history_count and error_string_too_long are the same shape: General is always loaded, and Search is loaded on the search page.
  • The two theme option headings sit behind theme_variants / has_dark_mode, and the default theme sets neither, so that branch does not run on a stock install and I could not exercise it. The evidence is the language files themselves plus the disagreeing sibling calls.
  • token_verify_fail needs a failed token in the upgrader; I did not stage that.

The sweep script is 60 lines and finds this class of mistake with no false positives once concatenated keys (getTxt('icon_' . $x, …)) are excluded. Happy to contribute it as a CI step alongside the unimported-class check offered in #9395 if that is wanted — neither phplint nor php-cs-fixer can see this, and the failure is silent rather than loud.

Found while splitting #7933; this is not part of the theme itself, so it goes straight to release-3.0.

Issues References (Fixes|Related|Closes)

Related to #7933

Lang::getTxt() takes a file: argument naming the language file the string
lives in, loads it, and returns an empty string when the key still is not
there. Nine calls name a file that does not define the key they ask for.

Where the right file happens to be loaded by something else on that page,
the lookup survives; where it is not, the string comes back empty. Two are
certainly empty:

 - MarkdownParser asked for quote_expand, which is the *admin setting*
   "Minimum quote height to add an expand link on large quotes", and lives
   in Admin. The label wanted is code_expand. Since the value ends up in
   data-expand-txt and script.js only builds the button when that attribute
   has a value, a fenced code block in Markdown never got its Expand button.
 - ThemeOptions asked for 'THemes', with a capital H, so on a case sensitive
   filesystem no file is loaded at all.

The rest name a real file that simply does not hold the string: the two
theme option headings are in Profile (as the same two calls in ThemeOptions
already say), invalid_credentials and edit_history_count are in General,
error_string_too_long is in Search, token_verify_fail is in Errors, and
edit_language_entries_add is in ManageSettings.

Signed-off-by: Mathias Papenbrock <mathiaspapealbert@hotmail.com>
Signed-off-by: albertlast <mathiaspapealbert@hotmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Localization Language & internationalization

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants