Making WordPress.org


Ignore:
Timestamp:
03/01/2021 06:13:18 AM (3 years ago)
Author:
dd32
Message:

Translate: Japanese doesn't need <em> tags, don't trigger a warning when it's missing.

See #5643.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-custom-warnings/wporg-gp-custom-warnings.php

    r10730 r10731  
    121121     *  - The value of translatable/url attributes is excluded from the error message if it's not related to the issue at hand.
    122122     *  - Tags are sorted, <em>One</em> <strong>Two</strong> can be translated as <strong>foo</strong> <em>bar</em> without generating warning.
     123     *  - Japanese can remove `<em>` tags.
    123124     *  - TODO: Tags are not validated to be nested correctly. GlotPress handles this by validating the ordering of the tags remained the same.
    124      *  - TODO: Allow Japanese (and other locales?) remove certain style/formatting tags that don't apply in the locale.
     125     *  - TODO: Extend/abstract the locales which can remove certain tags.
    125126     *
    126127     * @param string    $original    The source string.
     
    140141        if ( preg_match_all( $tag_re, $translation, $m ) ) {
    141142            $translation_parts = $m[1];
     143        }
     144
     145        // Allow Japanese to exclude <em>. TODO: Abstract this / extend it to all languages affected / extend to full list of tags.
     146        if ( count( $original_parts ) > count( $translation_parts ) ) {
     147
     148            $languages_without_italics = [
     149                'ja',
     150                // 'ko', 'zh', 'zh-hk', 'zh-cn', 'zh-sg', 'zh-tw' ??
     151            ];
     152
     153            // Remove Italic requirements.
     154            if ( in_array( $locale->slug, $languages_without_italics, true ) ) {
     155                $original_parts = array_diff( $original_parts, [ '<em>', '</em>', '<i>', '</i>' ] );
     156            }
    142157        }
    143158
Note: See TracChangeset for help on using the changeset viewer.