CompilesTranslations.php 1.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace Illuminate\View\Compilers\Concerns;
  3. trait CompilesTranslations
  4. {
  5. /**
  6. * Compile the lang statements into valid PHP.
  7. *
  8. * @param string $expression
  9. * @return string
  10. */
  11. protected function compileLang($expression)
  12. {
  13. if (is_null($expression)) {
  14. return '<?php $__env->startTranslation(); ?>';
  15. } elseif ($expression[1] === '[') {
  16. return "<?php \$__env->startTranslation{$expression}; ?>";
  17. }
  18. return "<?php echo app('translator')->getFromJson{$expression}; ?>";
  19. }
  20. /**
  21. * Compile the end-lang statements into valid PHP.
  22. *
  23. * @return string
  24. */
  25. protected function compileEndlang()
  26. {
  27. return '<?php echo $__env->renderTranslation(); ?>';
  28. }
  29. /**
  30. * Compile the choice statements into valid PHP.
  31. *
  32. * @param string $expression
  33. * @return string
  34. */
  35. protected function compileChoice($expression)
  36. {
  37. return "<?php echo app('translator')->choice{$expression}; ?>";
  38. }
  39. }