PageRenderTime 42ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/core/Translate/Filter/ByBaseTranslations.php

https://github.com/CodeYellowBV/piwik
PHP | 65 lines | 34 code | 10 blank | 21 comment | 5 complexity | 5407e749092f592c6618cb44abf4fe2c MD5 | raw file
Possible License(s): LGPL-3.0, JSON, MIT, GPL-3.0, LGPL-2.1, GPL-2.0, AGPL-1.0, BSD-2-Clause, BSD-3-Clause
  1. <?php
  2. /**
  3. * Piwik - free/libre analytics platform
  4. *
  5. * @link http://piwik.org
  6. * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
  7. *
  8. */
  9. namespace Piwik\Translate\Filter;
  10. /**
  11. */
  12. class ByBaseTranslations extends FilterAbstract
  13. {
  14. protected $baseTranslations = array();
  15. /**
  16. * Sets base translations
  17. *
  18. * @param array $baseTranslations
  19. */
  20. public function __construct($baseTranslations = array())
  21. {
  22. $this->baseTranslations = $baseTranslations;
  23. }
  24. /**
  25. * Removes all translations that aren't present in the base translations set in constructor
  26. *
  27. * @param array $translations
  28. *
  29. * @return array filtered translations
  30. */
  31. public function filter($translations)
  32. {
  33. $cleanedTranslations = array();
  34. foreach ($translations AS $pluginName => $pluginTranslations) {
  35. if (empty($this->baseTranslations[$pluginName])) {
  36. $this->filteredData[$pluginName] = $pluginTranslations;
  37. continue;
  38. }
  39. foreach ($pluginTranslations as $key => $translation) {
  40. if (isset($this->baseTranslations[$pluginName][$key])) {
  41. $cleanedTranslations[$pluginName][$key] = $translation;
  42. }
  43. }
  44. if (!empty($cleanedTranslations[$pluginName])) {
  45. $diff = array_diff($translations[$pluginName], $cleanedTranslations[$pluginName]);
  46. } else {
  47. $diff = $translations[$pluginName];
  48. }
  49. if (!empty($diff)) {
  50. $this->filteredData[$pluginName] = $diff;
  51. }
  52. }
  53. return $cleanedTranslations;
  54. }
  55. }