PageRenderTime 43ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/core/Translate/Filter/EmptyTranslations.php

https://github.com/CodeYellowBV/piwik
PHP | 47 lines | 22 code | 8 blank | 17 comment | 4 complexity | 9dd40a42ee9e0ffed119e63185b316f3 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 EmptyTranslations extends FilterAbstract
  13. {
  14. /**
  15. * Removes all empty translations
  16. *
  17. * @param array $translations
  18. *
  19. * @return array filtered translations
  20. */
  21. public function filter($translations)
  22. {
  23. $translationsBefore = $translations;
  24. foreach ($translations AS $plugin => &$pluginTranslations) {
  25. $pluginTranslations = array_filter($pluginTranslations, function ($value) {
  26. return !empty($value) && '' != trim($value);
  27. });
  28. $diff = array_diff($translationsBefore[$plugin], $pluginTranslations);
  29. if (!empty($diff)) {
  30. $this->filteredData[$plugin] = $diff;
  31. }
  32. }
  33. // remove plugins without translations
  34. $translations = array_filter($translations, function ($value) {
  35. return !empty($value) && count($value);
  36. });
  37. return $translations;
  38. }
  39. }