WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 4 years ago

Last modified 4 years ago

#7164 closed enhancement (fixed)

Automatic text replacements should be localized

Reported by: nico.r Owned by:
Milestone: 2.8 Priority: low
Severity: minor Version: 2.6
Component: I18N Keywords: needs-patch wptexturize
Focuses: Cc:

Description

In wp-includes/formatting.php, function wptexturize(string) does some text replacing, like replacement of straight quotes (U+0022) into curly quotes (U+201C and U+201D), but the replacements are specific to the en_US locale. For example, the correct quotation marks in de_DE are U+201E and U+201C.

As the replacement arrays can AFAIK not be expressed (or only with difficulties) in PO translation files, there is some need for providing a means of adding a language-specific script file.

Attached patch adds a function get_lang_php() to wp-includes/l10n.php which returns the name of a locale-specific PHP script. This new function is used in wp-includes/formatting.php in order to retrieve the script name; then this script is included.

The patch also adds two locale-specific script files, one for en_US, and one for de_DE. The en_US file simply contains the replacement patterns and strings which are currently present in wp-includes/formatting.php (they are moved by the patch). The de_DE file contains almost the same arrays, but adapted a little bit for German. Please note that the directory wp-content/languages/, in which these two files are placed, is currently not present on the trunk in the WordPress SVN repository.

It is expected that translators are going to provide language-specific PHP scripts, or (if they do not know PHP scripting or regular expressions) information about what replacements should be included in these, so that developers can add the appropriate regular expressions and replacement texts.

It is further expected that the new get_lang_php() mechanism will be used in other parts of the WordPress code or by new code parts or modules. It is useful in all cases in which locale-specific scripting is needed (i.e. when things cannot be expressed in PO translation files).

The patch applies to r8152 (current HEAD of trunk) in the WordPress SVN repository.
The function comment for get_lang_php() in wp-includes/l10n.php should be changed (fix “@since” comment) before the file is committed.

Attached patch is currently running on a production system with WordPress 2.5.1.

Attachments (1)

wordpress-r8152-localized_texturize-1.patch (4.5 KB) - added by nico.r 6 years ago.
Patch providing support for per-locale PHP scripts

Download all attachments as: .zip

Change History (6)

nico.r6 years ago

Patch providing support for per-locale PHP scripts

comment:1 thee176 years ago

  • Milestone set to 2.6
  • Version set to 2.6

comment:2 ryan5 years ago

  • Keywords needs-patch added; has-patch tested removed

We already load locale specific php files from wp-content/languages.

The arrays could be moved into WP_Locale. All locales should use the current defaults unless overridden.

comment:3 Denis-de-Bernardy5 years ago

  • Milestone changed from 2.9 to Future Release

comment:4 nbachiyski4 years ago

  • Resolution set to fixed
  • Status changed from new to closed

This was fixed in [11504]

comment:5 nacin4 years ago

  • Milestone changed from Future Release to 2.8
Note: See TracTickets for help on using tickets.