[ Index ]

PHP Cross Reference of GlotPress

title

Body

[close]

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

Translation warnings API

File Size: 812 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.

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

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

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

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

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

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

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.
return: array|null Null if no issues have been found, otherwise an array
since: 1.0.0

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.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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.

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

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>`

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

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

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

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>

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

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

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



Generated: Fri Jul 30 01:02:03 2021 Cross-referenced by PHPXref 0.7.1