Simple Machines Community Forum

SMF Support => Language Specific Support => Topic started by: viulian on December 13, 2007, 05:45:41 AM

Title: Script to diff two language files.
Post by: viulian on December 13, 2007, 05:45:41 AM
SMF Version: SMF 1.1.4
Mods installed:
Using default theme: yes
Link to site: http://www.lovetime.ro (http://www.lovetime.ro)

Hello!

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:


die "Usage langdiff.pl file1 file2\n" if $#ARGV != 1;
open(f1, "< $ARGV[0]") or die "Unable to open $ARGV[0]";
while(<f1>)
{
chop;
if ($_ =~ m/\$txt\['(.*?)'\]/)
{
$source{$1} = $1;
}
}
close(fl);

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

# 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 langdiff.pl 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:

> 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..