add_translations.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. use Drupal\Core\StringTranslation\TranslatableMarkup;
  3. // Lisa tõlge "Access denied" -> "Ligipääs keelatud" (et).
  4. $translation = [
  5. 'Access denied' => 'Ligipääs keelatud',
  6. 'You are not authorized to access this page.' => 'Sul puudub õigus antud lehte vaadata.',
  7. ];
  8. foreach ($translation as $source => $target) {
  9. // Kontrolli kas source juba olemas.
  10. $lid = \Drupal::database()->select('locales_source', 'ls')
  11. ->fields('ls', ['lid'])
  12. ->condition('source', $source)
  13. ->condition('context', '')
  14. ->execute()->fetchField();
  15. if (!$lid) {
  16. $lid = \Drupal::database()->insert('locales_source')
  17. ->fields(['source' => $source, 'context' => '', 'version' => ''])
  18. ->execute();
  19. echo "SOURCE_ADDED: $source\n";
  20. }
  21. // Lisa tõlge (et).
  22. $exists = \Drupal::database()->select('locales_target', 'lt')
  23. ->fields('lt', ['lid'])
  24. ->condition('lid', $lid)
  25. ->condition('language', 'et')
  26. ->execute()->fetchField();
  27. if (!$exists) {
  28. \Drupal::database()->insert('locales_target')
  29. ->fields([
  30. 'lid' => $lid,
  31. 'language' => 'et',
  32. 'translation' => $target,
  33. 'customized' => 1,
  34. ])
  35. ->execute();
  36. echo "TRANSLATION_ADDED: $source -> $target\n";
  37. } else {
  38. \Drupal::database()->update('locales_target')
  39. ->fields(['translation' => $target, 'customized' => 1])
  40. ->condition('lid', $lid)
  41. ->condition('language', 'et')
  42. ->execute();
  43. echo "TRANSLATION_UPDATED: $source -> $target\n";
  44. }
  45. }