dev/translation#30 Move l10n resource dir under private files
authorElliott Eggleston <ejegg@ejegg.com>
Sun, 6 Oct 2019 16:24:18 +0000 (18:24 +0200)
committerTim Otten <totten@civicrm.org>
Mon, 27 Jan 2020 00:41:14 +0000 (16:41 -0800)
Looks under [civicrm.private]/l10n if that exists, falling back to
[civicrm.root]/l10n.

Since I18n::getResourceDirectory needs to be called from GenCode,
where we don't have the base directory defined, we make the l10n
path factory function consult new #define CIVICRM_L10N_BASEDIR first.

In GenCode itself, keep using the old location for now, but make
it possible to change the location with an env var as soon as we
update buildkit.

CRM/Core/Config/MagicMerge.php
CRM/Core/I18n.php
Civi/Core/Paths.php
xml/GenCode.php

index 84f27ed990f471fd1847a6b98e8b2ec9d35e41ca..401c0c0ef5c91f78e07e1dc6adaf47adae60cf74 100644 (file)
@@ -178,6 +178,7 @@ class CRM_Core_Config_MagicMerge {
       // Option: `restrict` - auto-restrict remote access
       'configAndLogDir' => ['path', 'civicrm.log', ['mkdir', 'restrict']],
       'templateCompileDir' => ['path', 'civicrm.compile', ['mkdir', 'restrict']],
+      'l10nDir' => ['path', 'civicrm.l10n', ['mkdir', 'restrict']],
 
       // "setting-path" properties are settings with special filtering
       // to return normalized file paths.
index be23d592ff0ca6e440e674d393760947fa3f5e0a..8a97d428c29709c866a4e9932291d0cd1ac684a1 100644 (file)
@@ -282,11 +282,7 @@ class CRM_Core_I18n {
    * @return string
    */
   public static function getResourceDir() {
-    static $dir = NULL;
-    if ($dir === NULL) {
-      $dir = dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'l10n' . DIRECTORY_SEPARATOR;
-    }
-    return $dir;
+    return \Civi::paths()->getPath('[civicrm.l10n]/.');
   }
 
   /**
index 29bd7393d04d136a774eb417f329c69c2f08dcd7..a4ab40c220209185ca468a44518fdf8d313c80f6 100644 (file)
@@ -78,6 +78,12 @@ class Paths {
           'path' => defined('CIVICRM_TEMPLATE_COMPILEDIR') ? CIVICRM_TEMPLATE_COMPILEDIR : \Civi::paths()->getPath('[civicrm.private]/templates_c'),
         ];
       })
+      ->register('civicrm.l10n', function () {
+        $dir = defined('CIVICRM_L10N_BASEDIR') ? CIVICRM_L10N_BASEDIR : \Civi::paths()->getPath('[civicrm.private]/l10n');
+        return [
+          'path' => is_dir($dir) ? $dir : \Civi::paths()->getPath('[civicrm.root]/l10n'),
+        ];
+      })
       ->register('wp.frontend.base', function () {
         return ['url' => rtrim(CIVICRM_UF_BASEURL, '/') . '/'];
       })
index cee7f1475a5df5da572df96fdb93fb333a6454bd..01b541c9bdda5857b18d8cebf0f85ac564d52fda 100644 (file)
@@ -27,6 +27,7 @@ date_default_timezone_set('UTC');
 
 define('CIVICRM_UF', 'Drupal');
 define('CIVICRM_UF_BASEURL', '/');
+define('CIVICRM_L10N_BASEDIR', getenv('CIVICRM_L10N_BASEDIR') ? getenv('CIVICRM_L10N_BASEDIR') : __DIR__ . '/../l10n');
 
 require_once 'CRM/Core/ClassLoader.php';
 CRM_Core_ClassLoader::singleton()->register();