Overriding translations idea

Permalink
Hi,

Maybe it is already possible an I missed it, but I ran into some problems.

When using a (random) package, it can be translated (or already is). When you want to change that translation, you can overwrite the messages.mo file within the package but your changes will be lost when updating the package.

My solution to this, is a little change in the package.php module.

Within the package module, the package translation file is loaded from the /packages/package/languages/xx_XX/LC_MESSAGES/messages.mo.
The change I made is that it will first look in the root/languages/xx_XX/LC_MESSAGES/package_handle.mo
It that file exists, then it will use that one, else it will look for it in the package itself.
This way you can override the language file for a package, even when there is no translation file at all.

Is this a good idea to handle it this way? Or is there already something else I can do/use?

The package.php module (root/modules/package.php)

<?php 
defined('C5_EXECUTE') or die("Access Denied.");
class PackageList extends Concrete5_Model_PackageList {}
class Package extends Concrete5_Model_Package {
   public function setupPackageLocalization($locale = null, $key = null) {
      $translate = Localization::getTranslate();
      if (is_object($translate)) {
         $path = $this->getPackagePath() . '/' . DIRNAME_LANGUAGES;
         if(!isset($locale) || !strlen($locale)) {
            $locale = ACTIVE_LOCALE;
         }
         if(!isset($key)) {
            $key = $locale;
         }
         // We first check the language directory if any PACKAGE_HANDLE.mo file exists.


PS. When package developers use the t() function in their package, they should add an (empty) .po file as well. Will make life a bit easier ;)

SnefIT