class-configuration-translations.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * WPSEO plugin file.
  4. *
  5. * @package WPSEO\Admin\ConfigurationUI
  6. */
  7. /**
  8. * Class WPSEO_Configuration_Structure
  9. */
  10. class WPSEO_Configuration_Translations {
  11. /** @var array Registered steps */
  12. protected $translations = array();
  13. /** @var string The locale */
  14. protected $locale;
  15. /**
  16. * Sets the translations based on the file.
  17. *
  18. * @param string $locale The locale to retreive the translations for.
  19. */
  20. public function __construct( $locale ) {
  21. $this->locale = $locale;
  22. $this->translations = $this->get_translations_from_file();
  23. }
  24. /**
  25. * Retrieve the translations
  26. *
  27. * @return array
  28. */
  29. public function retrieve() {
  30. return $this->translations;
  31. }
  32. /**
  33. * Retrieves the translations from the JSON-file.
  34. *
  35. * @return array Array with the translations.
  36. */
  37. protected function get_translations_from_file() {
  38. $file = plugin_dir_path( WPSEO_FILE ) . 'languages/yoast-components-' . $this->locale . '.json';
  39. if ( file_exists( $file ) ) {
  40. $file = file_get_contents( $file );
  41. if ( is_string( $file ) && $file !== '' ) {
  42. return json_decode( $file, true );
  43. }
  44. }
  45. return array();
  46. }
  47. }