ArrayLoader.php 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace Illuminate\Translation;
  3. use Illuminate\Contracts\Translation\Loader;
  4. class ArrayLoader implements Loader
  5. {
  6. /**
  7. * All of the translation messages.
  8. *
  9. * @var array
  10. */
  11. protected $messages = [];
  12. /**
  13. * Load the messages for the given locale.
  14. *
  15. * @param string $locale
  16. * @param string $group
  17. * @param string $namespace
  18. * @return array
  19. */
  20. public function load($locale, $group, $namespace = null)
  21. {
  22. $namespace = $namespace ?: '*';
  23. if (isset($this->messages[$namespace][$locale][$group])) {
  24. return $this->messages[$namespace][$locale][$group];
  25. }
  26. return [];
  27. }
  28. /**
  29. * Add a new namespace to the loader.
  30. *
  31. * @param string $namespace
  32. * @param string $hint
  33. * @return void
  34. */
  35. public function addNamespace($namespace, $hint)
  36. {
  37. //
  38. }
  39. /**
  40. * Add a new JSON path to the loader.
  41. *
  42. * @param string $path
  43. * @return void
  44. */
  45. public function addJsonPath($path)
  46. {
  47. //
  48. }
  49. /**
  50. * Add messages to the loader.
  51. *
  52. * @param string $locale
  53. * @param string $group
  54. * @param array $messages
  55. * @param string|null $namespace
  56. * @return $this
  57. */
  58. public function addMessages($locale, $group, array $messages, $namespace = null)
  59. {
  60. $namespace = $namespace ?: '*';
  61. $this->messages[$namespace][$locale][$group] = $messages;
  62. return $this;
  63. }
  64. /**
  65. * Get an array of all the registered namespaces.
  66. *
  67. * @return array
  68. */
  69. public function namespaces()
  70. {
  71. return [];
  72. }
  73. }