Language overrides

Hi All,

Has anyone else had any trouble with language overrides in a plugin on upgrading to Elgg1.5.  It is simply not working for me.  Has the mechanism for language overrides changed?


  • Matt, Elgg 1.5 broke language overrides. You need to modify add_translation() to get it working again.

    It should look like this:

                        $CONFIG->translations[$country_code] = array_merge($CONFIG->translations[$country_code],$language_array);


    And not like this:                   

    //$CONFIG->translations[$country_code] += $language_array;

  • Thanks a lot.  What file is add_translation() located in?  Also, have you reported this as a bug on trac?

  • Yes, I've reported it ( The file is /engine/lib/languages.php

  • This is a known problem.

    The issue with the array_merge method is that it turns out to be dog slow, causing an unacceptible performance hit as the number of plugins and language files increased.

    I'm surprised that += doesn't clobber existing keys, but since it doesn't perhaps the following logic would work and still maintain the performance boost of using the operator rather than array_merge:

     $language_array += $CONFIG->translations[$country_code];

     $CONFIG->translations[$country_code] = $language_array;


  • According to the PHP documentation "The + operator appends elements of remaining keys from the right handed array to the left handed, whereas duplicated keys are NOT overwritten." Both + and += map to the same function add_function() which calls a hash merge function with the override parameter set to off.

    If language file loading is a significant part of the page load time, it would seem that caching the results would be very useful.

  • @Cash

    Your suggestion didn't work for me except that is broke anything related to that function.

    @Marcus Povey

    Your solution gave me this:

    Fatal error: Unsupported operand types in /mysite/elgg/engine/lib/languages.php on line 39

  • I think they both should work. Mine was just the original code from Elgg 1.2. 

    Try this:

    $CONFIG->translations[$country_code] = $language_array + $CONFIG->translations[$country_code];