Class used to register built-in translation warnings.

since 1.0.0
package GlotPress

 Methods

Registers all methods starting with `warning_` as built-in warnings.

add_all(\GP_Translation_Warnings $translation_warnings) 

Parameters

$translation_warnings

\GP_Translation_Warnings

Instance of GP_Translation_Warnings.

Checks whether lengths of source and translation differ too much.

warning_length(string $original, string $translation, \GP_Locale $locale) : string | true
since 1.0.0
access public

Parameters

$original

string

The source string.

$translation

string

The translation.

$locale

\GP_Locale

The locale of the translation.

Returns

stringtrueTrue if check is OK, otherwise warning message.

Adds a warning for changing plain-text URLs.

warning_mismatching_urls(string $original, string $translation) : string | true

This allows for the scheme to change, and for some domains to change to a subdomain.

since 3.0.0
access public

Parameters

$original

string

The original string.

$translation

string

The translated string.

Returns

stringtrueTrue if check is OK, otherwise warning message.

Adds a warning for changing placeholders.

warning_named_placeholders(string $original, string $translation) : string | true

This only supports placeholders in the format of '###[A-Za-z_-]+###'.

todo Check that the number of each type of placeholders are the same in the original and in the translation
since 3.0.0
access public

Parameters

$original

string

The original string.

$translation

string

The translated string.

Returns

stringtrue

Checks whether PHP placeholders are missing or have been added.

warning_placeholders(string $original, string $translation, \GP_Locale $locale) : string | true

The default regular expression: bcdefgosuxEFGX are standard printf placeholders. % is included to allow/expect %%. l is included for wp_sprintf_l()'s custom %l format. @ is included for Swift (as used for iOS mobile app) %@ string format.

since 1.0.0
access public

Parameters

$original

string

The source string.

$translation

string

The translation.

$locale

\GP_Locale

The locale of the translation.

Returns

stringtrueTrue if check is OK, otherwise warning message.

Checks whether a translation does begin on newline.

warning_should_begin_on_newline(string $original, string $translation, \GP_Locale $locale) : string | true
since 1.0.0
access public

Parameters

$original

string

The source string.

$translation

string

The translation.

$locale

\GP_Locale

The locale of the translation.

Returns

stringtrueTrue if check is OK, otherwise warning message.

Checks whether a translation does end on newline.

warning_should_end_on_newline(string $original, string $translation, \GP_Locale $locale) : string | true
since 1.0.0
access public

Parameters

$original

string

The source string.

$translation

string

The translation.

$locale

\GP_Locale

The locale of the translation.

Returns

stringtrueTrue if check is OK, otherwise warning message.

Checks whether a translation doesn't begin on newline.

warning_should_not_begin_on_newline(string $original, string $translation, \GP_Locale $locale) : string | true
since 1.0.0
access public

Parameters

$original

string

The source string.

$translation

string

The translation.

$locale

\GP_Locale

The locale of the translation.

Returns

stringtrueTrue if check is OK, otherwise warning message.

Checks whether a translation doesn't end on newline.

warning_should_not_end_on_newline(string $original, string $translation, \GP_Locale $locale) : string | true
since 1.0.0
access public

Parameters

$original

string

The source string.

$translation

string

The translation.

$locale

\GP_Locale

The locale of the translation.

Returns

stringtrueTrue if check is OK, otherwise warning message.

Checks whether HTML tags are missing or have been added.

warning_tags(string $original, string $translation, \GP_Locale $locale) : string | true
todo Validate if the HTML is in the same order in function of the language. Validate nesting of HTML is same.
since 1.0.0
access public

Parameters

$original

string

The source string.

$translation

string

The translation.

$locale

\GP_Locale

The locale of the translation.

Returns

stringtrueTrue if check is OK, otherwise warning message.

Adds a warning for adding unexpected percent signs in a sprintf-like string.

warning_unexpected_sprintf_token(string $original, string $translation) : boolean | string

This is to catch translations for originals like this:

  • Original: <a href="%s">100 percent</a>
  • Submitted translation: <a href="%s">100%</a>
  • Proper translation: <a href="%s">100%%</a>
since 3.0.0
access public

Parameters

$original

string

The original string.

$translation

string

The translated string.

Returns

booleanstring

Counts the placeholders in a string.

_placeholders_counts(string $string, string $re) : array
since 1.0.0
access private

Parameters

$string

string

The string to search.

$re

string

Regular expressions to match placeholders.

Returns

arrayAn array with counts per placeholder.

Checks if the HTML tags are in correct order

check_valid_html(array $original_parts, array $translation_parts) : string | true

Returns the values from the href and the src

get_values_from_href_src(array $content) : array
since 3.0.0
access private

Parameters

$content

array

The original array.

Returns

array

 Properties

 

List of domains with allowed changes to their own subdomains

$allowed_domain_changes : array

Default

array('wordpress.org' => '[^.]+\.wordpress\.org', 'wordpress.com' => '[^.]+\.wordpress\.com', 'en.gravatar.com' => '[^.]+\.gravatar\.com', 'en.wikipedia.org' => '[^.]+\.wikipedia\.org')
since 3.0.0
access public
 

List of languages without italics

$languages_without_italics : array

Default

array('ja', 'ko', 'zh', 'zh-hk', 'zh-cn', 'zh-sg', 'zh-tw')
since 3.0.0
access public
 

List of locales which are excluded from length checks.

$length_exclude_languages : array

Default

array('art-xemoji', 'ja', 'ko', 'zh', 'zh-hk', 'zh-cn', 'zh-sg', 'zh-tw')
since 1.0.0
access public
 

Lower bound for length checks.

$length_lower_bound : float

Default

0.2
since 1.0.0
access public
 

Upper bound for length checks.

$length_upper_bound : float

Default

5.0
since 1.0.0
access public