[ Index ]

PHP Cross Reference of GlotPress

title

Body

[close]

/gp-includes/ -> warnings.php (summary)

Translation warnings API

File Size: 818 lines (26 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 2 classes

GP_Translation_Warnings:: (4 methods):
  add()
  remove()
  has()
  check()

GP_Builtin_Translation_Warnings:: (15 methods):
  warning_length()
  warning_tags()
  warning_placeholders()
  _placeholders_counts()
  warning_should_begin_on_newline()
  warning_should_not_begin_on_newline()
  warning_should_end_on_newline()
  warning_should_not_end_on_newline()
  warning_mismatching_urls()
  warning_unexpected_sprintf_token()
  add_all()
  warning_named_placeholders()
  get_values_from_href_src()
  check_valid_html()
  links_without_url_and_placeholders_are_equal()


Class: GP_Translation_Warnings  - X-Ref

Class used to handle translation warnings.

add( $id, $callback )   X-Ref
Adds a callback for a new warning.

since: 1.0.0
param: string   $id       Unique ID of the callback.
param: callable $callback The callback.

remove( $id )   X-Ref
Removes an existing callback for a warning.

since: 1.0.0
param: string $id Unique ID of the callback.

has( $id )   X-Ref
Checks whether a callback exists for an ID.

return: bool True if exists, false if not.
since: 1.0.0
param: string $id Unique ID of the callback.

check( $singular, $plural, $translations, $locale )   X-Ref
Checks translations for any issues/warnings.

return: array|null Null if no issues have been found, otherwise an array
since: 1.0.0
param: string    $singular     The singular form of an original string.
param: string    $plural       The plural form of an original string.
param: string[]  $translations An array of translations for an original.
param: GP_Locale $locale       The locale of the translations.

Class: GP_Builtin_Translation_Warnings  - X-Ref

Class used to register built-in translation warnings.

warning_length( $original, $translation, $locale )   X-Ref
Checks whether lengths of source and translation differ too much.

return: string|true True if check is OK, otherwise warning message.
since: 1.0.0
param: string    $original    The source string.
param: string    $translation The translation.
param: GP_Locale $locale      The locale of the translation.

warning_tags( $original, $translation, $locale )   X-Ref
Checks whether HTML tags are missing or have been added.

return: string|true True if check is OK, otherwise warning message.
since: 1.0.0
param: string    $original    The source string.
param: string    $translation The translation.
param: GP_Locale $locale      The locale of the translation.

warning_placeholders( $original, $translation, $locale )   X-Ref
Checks whether PHP placeholders are missing or have been added.

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.

return: string|true True if check is OK, otherwise warning message.
since: 1.0.0
param: string    $original    The source string.
param: string    $translation The translation.
param: GP_Locale $locale      The locale of the translation.

_placeholders_counts( $string, $re )   X-Ref
Counts the placeholders in a string.

return: array An array with counts per placeholder.
since: 1.0.0
param: string $string The string to search.
param: string $re     Regular expressions to match placeholders.

warning_should_begin_on_newline( $original, $translation, $locale )   X-Ref
Checks whether a translation does begin on newline.

return: string|true True if check is OK, otherwise warning message.
since: 1.0.0
param: string    $original    The source string.
param: string    $translation The translation.
param: GP_Locale $locale      The locale of the translation.

warning_should_not_begin_on_newline( $original, $translation, $locale )   X-Ref
Checks whether a translation doesn't begin on newline.

return: string|true True if check is OK, otherwise warning message.
since: 1.0.0
param: string    $original    The source string.
param: string    $translation The translation.
param: GP_Locale $locale      The locale of the translation.

warning_should_end_on_newline( $original, $translation, $locale )   X-Ref
Checks whether a translation does end on newline.

return: string|true True if check is OK, otherwise warning message.
since: 1.0.0
param: string    $original    The source string.
param: string    $translation The translation.
param: GP_Locale $locale      The locale of the translation.

warning_should_not_end_on_newline( $original, $translation, $locale )   X-Ref
Checks whether a translation doesn't end on newline.

return: string|true True if check is OK, otherwise warning message.
since: 1.0.0
param: string    $original    The source string.
param: string    $translation The translation.
param: GP_Locale $locale      The locale of the translation.

warning_mismatching_urls( $original, $translation )   X-Ref
Adds a warning for changing plain-text URLs.

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

return: string|true True if check is OK, otherwise warning message.
since: 3.0.0
param: string $original    The original string.
param: string $translation The translated string.

warning_unexpected_sprintf_token( $original, $translation )   X-Ref
Adds a warning for adding unexpected percent signs in a sprintf-like 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>`

return: bool|string
since: 3.0.0
param: string $original    The original string.
param: string $translation The translated string.

add_all( $translation_warnings )   X-Ref
Registers all methods starting with `warning_` as built-in warnings.

param: GP_Translation_Warnings $translation_warnings Instance of GP_Translation_Warnings.

warning_named_placeholders( string $original, string $translation )   X-Ref
No description

get_values_from_href_src( array $content )   X-Ref
Returns the values from the href and the src

return: array
since: 3.0.0
param: array $content The original array.

check_valid_html( array $original_parts, array $translation_parts )   X-Ref
Checks if the HTML tags are in correct order

Warns about HTML tags translations in incorrect order. For example:
- Original: <a></a>
- Translation: </a><a>

return: string|true True if check is OK, otherwise warning message.
param: array $original_parts     The original HTML tags.
param: array $translation_parts  The translation HTML tags.

links_without_url_and_placeholders_are_equal( string $original_links, string $translation_links )   X-Ref
Checks whether links that are not URL or placeholders are equal or not

return: array|true True if check is OK, otherwise warning message.
since: 3.0.0
param: string $original_links    The original links.
param: string $translation_links The translated links.



Generated: Thu Nov 21 01:01:07 2024 Cross-referenced by PHPXref 0.7.1