Skip to content

Instantly share code, notes, and snippets.

@damsfx
Last active February 22, 2023 18:21
Show Gist options
  • Save damsfx/6fcb2cf7a54845c1a8d525daaa67671f to your computer and use it in GitHub Desktop.
Save damsfx/6fcb2cf7a54845c1a8d525daaa67671f to your computer and use it in GitHub Desktop.
Check translations in WinterCMS/OctoberCMS

In command prompt run :

php artisan tinker
function array_diff_key_recursive(array $arr1, array $arr2) {
    $diff = array_diff_key($arr1, $arr2);
    $intersect = array_intersect_key($arr1, $arr2);
    
    foreach ($intersect as $k => $v) {
        if (is_array($arr1[$k]) && is_array($arr2[$k])) {
            $d = array_diff_key_recursive($arr1[$k], $arr2[$k]);
            
            if ($d) {
                $diff[$k] = $d;
            }
        }
    }

    return $diff;
};

function compare_Translate_files($path, $ref, $other, $file = 'lang') {
    $ref = include($path .'/lang/'. $ref .'/'. $file .'.php');
    $other = include($path .'/lang/'. $other .'/'. $file .'.php');

    return array_diff_key_recursive($ref, $other);
}


// Usage for backend translations
compare_translate_files('modules/backend', 'en', 'fr');
// or for a plugin
compare_translate_files('plugins/winter/blog', 'en', 'fr');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment