Quantcast
Channel: phpBB.com
Viewing all articles
Browse latest Browse all 2802

[3.3.x] Styles Support & Discussion • Proposal for custom language strings in styles

$
0
0
This is for the Customisations Team to consider.
Previous topic was here: Question about custom language strings

There is a better way of doing it, in that the custom strings will also be accessible to screen readers, so they can be used for things like aria-label. The old proposal did not allow this. Translation should be easier, due to not having to rely on CSS for pseudo elements. Translation is also arguably easier than the way it is done in extensions, because the string definitions are in plain text rather than PHP syntax.

Essentially it creates a language directory inside the usual template directory. This then contains directories for any supported language, and those contain .twig files that allow importing custom language strings to any phpBB template. The import process is handled with Twig in the template, and only a few lines of code are necessary. No extension is required. This has all been tested live, and works without any issues.

Directory tree goes like this:
  • Style_name
    • template
      • language
        1. en-gb
          • overall_header.twig
        2. et
          • overall_header.twig
        3. ro
          • overall_header.twig
Import code in the template (automatic fallback to en-gb if no file exists for the user's selected language):

Code:

{% set lang_file = "language/" ~ S_USER_LANG ~ "/overall_header.twig" %}{% if source(lang_file, ignore_missing=true) is not empty %}{% import lang_file as styleStrings %}{% else %}{% import "language/en-gb/overall_header.twig" as styleStrings %}{% endif %}

If the string is also required in a child template of overall_header.html, declare it as a global variable after importing:

Code:

{% set lang_file = "language/" ~ S_USER_LANG ~ "/overall_header.twig" %}{% if source(lang_file, ignore_missing=true) is not empty %}{% import lang_file as styleStrings %}{% else %}{% import "language/en-gb/overall_header.twig" as styleStrings %}{% endif %}{% set testString = styleStrings.testString %}

Content of the .twig files in the language directory is just a list of very simple macros, with content in plain text:

Code:

{% macro testString() %} My old man's a dustman {% endmacro %}

Code:

{% macro testString() %} Bătrânul meu e un gunoier {% endmacro %}
This is easily adaptable to any template and any language, at the cost of very little code, and with very easy translation.

Would the Customisations Team consider allowing this method for approval of styles that (judiciously) use custom language strings?

Statistics: Posted by Gumboots — Sat Apr 12, 2025 12:29 am



Viewing all articles
Browse latest Browse all 2802

Trending Articles