Author Topic: Script to diff two language files.  (Read 4717 times)

Offline viulian

  • Jr. Member
  • **
  • Posts: 235
Script to diff two language files.
« on: December 13, 2007, 05:45:41 AM »
SMF Version: SMF 1.1.4
Mods installed:
Using default theme: yes
Link to site:


I've created a file which does the diff between two language files, and specifies what keys are unique in each.

My main issue is that I offer my forum in English, Spanish, German and Romanian UTF-8 languages, however, most of the mods assume that the non UTF-8 language files are used.
So I always get the entries in Modifications.english.php instead of Modifications.english-utf8.php.

So I decided to create a small script that does the langdiff for me and tells me what keys from the Modification.english.php are missing from Modification.english-utf8.php

Then, I will langdiff the Modification.english-utf8.php with all the other languages and see what keys I am missing there.

Code is:

Code: [Select]
die "Usage file1 file2\n" if $#ARGV != 1;
open(f1, "< $ARGV[0]") or die "Unable to open $ARGV[0]";
if ($_ =~ m/\$txt\['(.*?)'\]/)
$source{$1} = $1;

open (f2, "< $ARGV[1]") or die "Unable to open $ARGV[1]";
while (<f2>)
if ($_ =~ m/\$txt\['(.*?)'\]/)
$dest{$1} = $1;

# diff part

while ( my($key, $value) = each(%source))
print "> $key\n" unless exists $dest{$key};
while ( my($key, $value) = each(%dest))
print "< $key\n" unless exists $source{$key};

Put this in file inside the default/languages directory and issue a command like

perl langdiff Modification.english.php Modification.english-utf8.php.

I get an output like this:

Code: [Select]
> filemanager
> poem
> youtube

This means that $txt['filemanager'] variable is found on the left file (first argument) and must be copied to the right file (second argument).

It can compare non uft with utf-8 files.

Hope it is usefull..