GravityView  2.17
The best, easiest way to display Gravity Forms entries on your website.
Public Member Functions | Static Public Member Functions | Data Fields | Private Member Functions | Private Attributes | Static Private Attributes
TranslationsPress_Updater Class Reference

Allows downloading and installing translations from TranslationsPress. More...

Public Member Functions

 convert_po_to_json ( $po_file, $json_file)
 Converts the PO file to JSON file by extracting only JavaScript translations. More...
 
 download_package ( $slug, $locale='')
 Downloads and installs the translations package for the specified plugin. More...
 
 get_available_languages ()
 Returns an array of locales the site has installed. More...
 
 get_exception ( $message, $method,... $args)
 Formats and returns an exception message. More...
 
 get_installed_translations ( $return_files=false)
 Returns an array of locales or .mo translation files found in the translations folder. More...
 
 get_installed_translations_data ()
 Returns header data from the installed translations for the current plugin. More...
 
 get_plugin_translations ()
 Gets the TranslationsPress data for the current plugin. More...
 
 get_remote_translations_data ()
 Gets the translation data from the TranslationsPress API. More...
 
 get_slug_from_locale ( $locale)
 Returns T15S slug for the language based on the WP locale. More...
 
 install ( $locale='')
 Installs translations for a given locale. More...
 
 install_translation ( $translation)
 Downloads and installs the given translation. More...
 
 is_transient_expired ()
 Determines if the cached TranslationsPress data needs refreshing. More...
 
 refresh_all_translations ()
 Refreshes the cached TranslationsPress data, if expired. More...
 
 set_all_translations ()
 Caches the TranslationsPress data, if not already cached. More...
 
 should_install ( $translation, $locale='')
 Determines if a translation should be installed. More...
 
 site_transient_update_plugins ( $value)
 Filters the translations transients to include the current plugin. More...
 
 translations_api ( $result, $requested_type, $args)
 Short-circuits translations API requests for private projects. More...
 

Static Public Member Functions

static get_instance ( $slug, $translations_path='')
 Returns an instance of this class for the given slug. More...
 

Data Fields

const T15S_API_EXPORT_URL = 'https://translationspress.com/app/gravitykit/{plugin_slug}/{language_slug}/default/export-translations'
 
const T15S_API_PACKAGES_URL = 'https://packages.translationspress.com/gravitykit/packages.json'
 
const T15S_TRANSIENT_EXPIRY = 12 * HOUR_IN_SECONDS
 
const T15S_TRANSIENT_KEY = 't15s-registry-gravitykit'
 

Private Member Functions

 __construct ( $slug, $translations_path='')
 Class constructor. More...
 

Private Attributes

 $_all_translations
 
 $_slug = ''
 
 $_translations_path = WP_LANG_DIR . '/plugins/'
 

Static Private Attributes

static $_instances = []
 

Detailed Description

Allows downloading and installing translations from TranslationsPress.

This is a modified version of the Gravity Forms' TranslationsPress_Updater class, which is based on the T15S library.

Since
1.0.0
See also
https://github.com/WP-Translations/t15s-registry
gravityforms/includes/class-translationspress-updater.php

Definition at line 28 of file TranslationsPress_Updater.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $slug,
  $translations_path = '' 
)
private

Class constructor.

Since
1.0.0
Parameters
string$slugThe plugin slug.
string$translations_pathTranslations storage path.

Definition at line 78 of file TranslationsPress_Updater.php.

Member Function Documentation

◆ convert_po_to_json()

convert_po_to_json (   $po_file,
  $json_file 
)

Converts the PO file to JSON file by extracting only JavaScript translations.

Since
1.0.0
1.0.1 New $json_file parameter and Exception when the PO file cannot be read/JSON file cannot be saved.
Parameters
string$po_fileFile with path to the PO file.
string$json_fileFile with path where the JSON file will be saved.
Exceptions
Exception
Returns
void

Definition at line 457 of file TranslationsPress_Updater.php.

References TranslationsPress_Updater\get_exception().

Referenced by TranslationsPress_Updater\install_translation().

◆ download_package()

download_package (   $slug,
  $locale = '' 
)

Downloads and installs the translations package for the specified plugin.

Since
1.0.0
Parameters
string$slugThe plugin slug.
string$localeThe locale when the site locale is changed or an empty string to install all the user available locales.
Exceptions
Exception
Returns
void

Definition at line 304 of file TranslationsPress_Updater.php.

◆ get_available_languages()

get_available_languages ( )

Returns an array of locales the site has installed.

Since
1.0.0
Returns
array

Definition at line 542 of file TranslationsPress_Updater.php.

Referenced by TranslationsPress_Updater\should_install().

◆ get_exception()

get_exception (   $message,
  $method,
  $args 
)

Formats and returns an exception message.

Since
1.0.0
Parameters
string$messageException message with placeholders for sprintf() replacement.
string$methodMethod throwing the exception.
mixed$args,...Variable-length argument lists for sprintf() replacement.
Returns
string

Definition at line 621 of file TranslationsPress_Updater.php.

References $args.

Referenced by TranslationsPress_Updater\convert_po_to_json(), TranslationsPress_Updater\get_remote_translations_data(), TranslationsPress_Updater\install(), and TranslationsPress_Updater\install_translation().

◆ get_installed_translations()

get_installed_translations (   $return_files = false)

Returns an array of locales or .mo translation files found in the translations folder.

Since
1.0.0
Parameters
bool$return_filesIndicates if the object should be keyed by locale (e.g., 'en_EN').
Returns
array

Definition at line 590 of file TranslationsPress_Updater.php.

Referenced by TranslationsPress_Updater\get_installed_translations_data().

◆ get_installed_translations_data()

get_installed_translations_data ( )

Returns header data from the installed translations for the current plugin.

Since
1.0.0
Returns
array

Definition at line 559 of file TranslationsPress_Updater.php.

References TranslationsPress_Updater\$_slug, and TranslationsPress_Updater\get_installed_translations().

Referenced by TranslationsPress_Updater\should_install().

◆ get_instance()

static get_instance (   $slug,
  $translations_path = '' 
)
static

Returns an instance of this class for the given slug.

Since
1.0.0
Parameters
string$slugThe plugin slug.
string$translations_pathTranslations storage path.
Returns
TranslationsPress_Updater

Definition at line 102 of file TranslationsPress_Updater.php.

Referenced by Framework\get_T15s_updater().

◆ get_plugin_translations()

get_plugin_translations ( )

Gets the TranslationsPress data for the current plugin.

Since
1.0.0
Exceptions
Exception
Returns
array

Definition at line 140 of file TranslationsPress_Updater.php.

References TranslationsPress_Updater\$_slug, and TranslationsPress_Updater\set_all_translations().

Referenced by TranslationsPress_Updater\install(), TranslationsPress_Updater\site_transient_update_plugins(), and TranslationsPress_Updater\translations_api().

◆ get_remote_translations_data()

get_remote_translations_data ( )

Gets the translation data from the TranslationsPress API.

Since
1.0.0
Exceptions
Exception
Returns
array

Definition at line 233 of file TranslationsPress_Updater.php.

References TranslationsPress_Updater\get_exception().

Referenced by TranslationsPress_Updater\set_all_translations().

◆ get_slug_from_locale()

get_slug_from_locale (   $locale)

Returns T15S slug for the language based on the WP locale.

This is used to access the export URL (e.g., https://translationspress.com/app/gravitykit/gk-gravitycalendar/<slug>/default/export-translations/)

Since
1.0.1
Parameters
string$localeWP language locale.
Returns
string|null T15S slug.

Definition at line 641 of file TranslationsPress_Updater.php.

References Arr\get().

Referenced by TranslationsPress_Updater\install_translation().

◆ install()

install (   $locale = '')

Installs translations for a given locale.

Since
1.0.0
Parameters
string$localeLocale for which to install the translation.
Exceptions
Exception
Returns
void

Definition at line 319 of file TranslationsPress_Updater.php.

References TranslationsPress_Updater\get_exception(), TranslationsPress_Updater\get_plugin_translations(), TranslationsPress_Updater\install_translation(), and TranslationsPress_Updater\should_install().

◆ install_translation()

install_translation (   $translation)

Downloads and installs the given translation.

Since
1.0.0
1.0.1 Download an extra file from the T15S API.
Parameters
array$translationThe translation data.
Exceptions
Exception
Returns
void

Definition at line 353 of file TranslationsPress_Updater.php.

References TranslationsPress_Updater\convert_po_to_json(), TranslationsPress_Updater\get_exception(), and TranslationsPress_Updater\get_slug_from_locale().

Referenced by TranslationsPress_Updater\install().

◆ is_transient_expired()

is_transient_expired ( )

Determines if the cached TranslationsPress data needs refreshing.

Since
1.0.0
Returns
bool

Definition at line 218 of file TranslationsPress_Updater.php.

Referenced by TranslationsPress_Updater\set_all_translations().

◆ refresh_all_translations()

refresh_all_translations ( )

Refreshes the cached TranslationsPress data, if expired.

Since
1.0.0
Exceptions
Exception
Returns
void

Definition at line 197 of file TranslationsPress_Updater.php.

References TranslationsPress_Updater\set_all_translations().

◆ set_all_translations()

set_all_translations ( )

Caches the TranslationsPress data, if not already cached.

Since
1.0.0
Exceptions
Exception
Returns
void

Definition at line 274 of file TranslationsPress_Updater.php.

References TranslationsPress_Updater\get_remote_translations_data(), and TranslationsPress_Updater\is_transient_expired().

Referenced by TranslationsPress_Updater\get_plugin_translations(), and TranslationsPress_Updater\refresh_all_translations().

◆ should_install()

should_install (   $translation,
  $locale = '' 
)

Determines if a translation should be installed.

Since
1.0.0
Parameters
array$translationThe translation data.
string$localeThe locale when the site locale is changed or an empty string to check all the user available locales.
Returns
bool

Definition at line 514 of file TranslationsPress_Updater.php.

References TranslationsPress_Updater\get_available_languages(), and TranslationsPress_Updater\get_installed_translations_data().

Referenced by TranslationsPress_Updater\install(), and TranslationsPress_Updater\site_transient_update_plugins().

◆ site_transient_update_plugins()

site_transient_update_plugins (   $value)

Filters the translations transients to include the current plugin.

Since
1.0.0
See also
wp_get_translation_updates()
Parameters
mixed$valueThe transient value.
Exceptions
Exception
Returns
object

Definition at line 159 of file TranslationsPress_Updater.php.

References TranslationsPress_Updater\$_slug, $value, TranslationsPress_Updater\get_plugin_translations(), and TranslationsPress_Updater\should_install().

◆ translations_api()

translations_api (   $result,
  $requested_type,
  $args 
)

Short-circuits translations API requests for private projects.

Since
1.0.0
Parameters
bool | array$resultThe result object (default: false).
string$requested_typeThe type of translations being requested.
object$argsTranslation API arguments.
Exceptions
Exception
Returns
bool|array

Definition at line 123 of file TranslationsPress_Updater.php.

References $args, and TranslationsPress_Updater\get_plugin_translations().

Field Documentation

◆ $_all_translations

$_all_translations
private

Definition at line 60 of file TranslationsPress_Updater.php.

◆ $_instances

$_instances = []
staticprivate

Definition at line 67 of file TranslationsPress_Updater.php.

◆ $_slug

$_slug = ''
private

◆ $_translations_path

$_translations_path = WP_LANG_DIR . '/plugins/'
private

Definition at line 53 of file TranslationsPress_Updater.php.

◆ T15S_API_EXPORT_URL

const T15S_API_EXPORT_URL = 'https://translationspress.com/app/gravitykit/{plugin_slug}/{language_slug}/default/export-translations'

Definition at line 35 of file TranslationsPress_Updater.php.

◆ T15S_API_PACKAGES_URL

const T15S_API_PACKAGES_URL = 'https://packages.translationspress.com/gravitykit/packages.json'

Definition at line 33 of file TranslationsPress_Updater.php.

◆ T15S_TRANSIENT_EXPIRY

const T15S_TRANSIENT_EXPIRY = 12 * HOUR_IN_SECONDS

Definition at line 31 of file TranslationsPress_Updater.php.

◆ T15S_TRANSIENT_KEY

const T15S_TRANSIENT_KEY = 't15s-registry-gravitykit'

Definition at line 29 of file TranslationsPress_Updater.php.


The documentation for this class was generated from the following file: