Jump to content


- - - - -

[MA23] Language File Comparison Tool v1.1


  • Please log in to reply
25 replies to this topic

#1 Martin

Martin

    But but, it's not only only!

  • Management
  • PipPipPipPipPipPipPipPipPipPip
  • 7,081 posts
  • Location:Hammerfest, Norway
  • Real Name:Martin Aronsen
  • IPB Version:v3.2.x
Contributor

Posted 07 September 2008 - 12:11 PM

Posted Image


File Name: [MA23] Language File Comparison Tool v1.1
File Submitter: m4rtin
File Submitted: 7 Sep 2008
File Updated: 17 Sep 2008
File Category: IP.Board v2.3.x & v2.2.x Tools

/*
* @DESC:
* This is a tool for comparing your custom IP.Board language files, with the default files.
* During upgrading, or other things, new language strings aren't added to these files, causing empty fields around the board.
*
* This tool will scan trough the default language folder (./cache/lang_cache/en), then the other language folder.
* If there are files in the default folder, that arne't in the other, it will be copied.
* It does not work the other way, as many language packs may contain irrelevant language files that you don't need.
* When the scanning is done, it will go trough each and every file to see if the language keys (the one used on the IP.Board template)
* are in both files. If some are missing, it will be printed in the result page.
*
* Due to the way lang_email_content.php is built up, I were not able to compare that file.
* You either have to do it manually, or just use the standard English version.
*
* @USAGE:
* Save this file as "langdiff.php", then change the two paths below this comment, then upload it to your forums root folder.
* Then access it using your web browser. When it's done, it should either show you a list of all the differences,
* or a page showing you that everything is up-to-date.
*
* @DISCLAIMER
* I do not take any responsibility for use of this tool.
* You should always take backups before installing or using 3rd party applications.
* In this case, you should back up "cache/lang_cache", just in case something should go wrong.
*
* @author: Martin Aronsen
* @web: http://www.invisionmodding.com
*/

There are no requirements for any installers, and it is compatible with all IPB versions as far as I know.

The instructions are found on the top of the file (langdiff.php), or here.

What's new?
v1.1 - Made it compatible with PHP4. If you use PHP5, no needs to worry.

Click here to download this file

#2 MindTooth

MindTooth

    Member

  • Members
  • PipPipPip
  • 26 posts
  • Location:Vinstra, NORWAY
  • Real Name:Birger J. Nordølum
  • IPB Version:v2.3.x

Posted 09 September 2008 - 06:43 PM

I appreciated this a lot. Helped me when I upgraded my board, and my translation did not had the new strings.

Birger ;)

#3 Tom

Tom

    Posting God

  • IM Supporters
  • PipPipPipPipPipPipPipPipPip
  • 1,541 posts
  • IPB Version:v2.3.x

Posted 11 September 2008 - 03:50 PM

Just a thanks, because I'm certain that I'll use it one day. Cheers m4rtin for another goodie!

#4 ilsaggio

ilsaggio

    Advanced Member

  • Banned
  • PipPipPipPip
  • 55 posts
  • IPB Version:v2.3.x

Posted 11 September 2008 - 06:04 PM

Fatal error: Call to undefined function: scandir() in .../forum/langdiff.php on line 58

;)

#5 Michael

Michael

    See code 431.322.12 of the Internet Privacy Act

  • Modders
  • PipPipPipPipPipPipPipPipPipPip
  • 22,042 posts
  • Location:Columbus, OH
  • Real Name:Michael McCune
  • IPB Version:v3.1.x
Contributor

Posted 11 September 2008 - 06:07 PM

It looks like the PHP function scandir() was introduced in PHP5, so I'm guessing this tool won't work for people still on PHP4.
Michael McCune - IPS Marketplace Moderator

My Stuff: My Forum · My Resources · My Tutorials
Contact Me: Email · Facebook · Twitter

#6 Martin

Martin

    But but, it's not only only!

  • Management
  • PipPipPipPipPipPipPipPipPipPip
  • 7,081 posts
  • Location:Hammerfest, Norway
  • Real Name:Martin Aronsen
  • IPB Version:v3.2.x
Contributor

Posted 11 September 2008 - 08:24 PM

Wow, didn't even think of those few people who are still using PHP4.

My hard drive just crashed on my main machine, so give me a day or so, and I'll come up with a fix.
Turned out to be just the SATA cable :)

Nope, it sure was broken ;)

#7 Trialga

Trialga

    Coder

  • IM Supporters
  • PipPipPipPipPip
  • 159 posts
  • Real Name:Bryan
  • IPB Version:v2.3.x

Posted 11 September 2008 - 09:01 PM

m4rtin, to save you some time, if you are going to change the scandir area to make it PHP 4 compatible, you can use the below code ;)

if (is_dir($yourdir))
{
	$dir = opendir($yourdir);
	
	while ($d = readdir($dir))
	{
		// do what you need to do here
		// $d is a file resource
	}
	
	closedir($dir);
}


#8 Martin

Martin

    But but, it's not only only!

  • Management
  • PipPipPipPipPipPipPipPipPipPip
  • 7,081 posts
  • Location:Hammerfest, Norway
  • Real Name:Martin Aronsen
  • IPB Version:v3.2.x
Contributor

Posted 11 September 2008 - 09:28 PM

Can anyone check to see if this creates any parse errors or anything?
I don't have PHP on my laptop, and is quite busy trying to recover my broken hard drive.

<?php

/*
 * @DESC:
 * This is a tool for comparing your custom IP.Board language files, with the default files.
 * During upgrading, or other things, new language strings aren't added to these files, causing empty fields around the board.
 * 
 * This tool will scan trough the default language folder (./cache/lang_cache/en), then the other language folder. 
 * If there are files in the default folder, that arne't in the other, it will be copied. 
 * It does not work the other way, as many language packs may contain irrelevant language files that you don't need.
 * When the scanning is done, it will go trough each and every file to see if the language keys (the one used on the IP.Board template) 
 * are in both files. If some are missing, it will be printed in the result page.
 *
 * Due to the way lang_email_content.php is built up, I were not able to compare that file. 
 * You either have to do it manually, or just use the standard English version. 
 *
 * @USAGE:
 * Save this file as "langdiff.php", then change the two paths below this comment, then upload it to your forums root folder. 
 * Then access it using your web browser. When it's done, it should either show you a list of all the differences,
 * or a page showing you that everything is up-to-date.
 *
 * @DISCLAIMER
 * I do not take any responsibility for use of this tool.
 * You should always take backups before installing or using 3rd party applications.
 * In this case, you should back up "cache/lang_cache", just in case something should go wrong.
 * 
 * @author: Martin Aronsen
 * @web: [url="http://www.invisionmodding.com"]http://www.invisionmodding.com[/url]
 */
 
// This should be left alone
define( 'DEFAULT_LANG_DIR', 'cache/lang_cache/en' );

// This is the one you might want to change
define( 'CUSTOM_LANG_DIR', 'cache/lang_cache/norsk-beta' );
 
if ( defined( 'IN_IPB' ) )
{
	print "<h1>Incorrect access</h1>You didn't follow the instructions. You should not access this file trough IP.Board.";
	exit();
}

class compareLangFiles
{
	var $customLangDir;
	var $defaultLangDir;
	var $langArray = array( 'defaultLang' => NULL, 'customLang' => NULL );
	var $diffArray = array();
	
	//-----------------------------------------
	// Scanning the language dirs,
	// and creating an array holding the file names
	//-----------------------------------------
	
	function scanDirs()
	{
		$customLangFiles = array();
		$defaultLangFiles = array();
		
		
		//Scan the language files
		if( version_compare( PHP_VERSION, '5.0.0', '<' ) )
		{
			// I'm using PHP4 ;)
			if( is_dir( $this->customLangDir ) )
			{
				$dh = opendir( $this->customLangDir );
				
				while( ( $fileName = readdir( $dh ) ) !== FALSE )
				{
					$customLangFiles[] = $fileName;
				}
				
				closedir( $dh );
			}
			
			if( is_dir( $this->defaultLangDir ) )
			{
				$dh = opendir( $this->defaultLangDir );
				
				while( ( $fileName = readdir( $dh ) ) !== FALSE )
				{
					$defaultLangFiles[] = $fileName;
				}
				
				closedir( $dh );
			}
		}
		else if( version_compare( PHP_VERSION, '5.0.0', '>=' ) )
		{
			$defaultLangFiles 	= scandir( $this->defaultLangDir );
			$customLangFiles 	= scandir( $this->customLangDir );
		}

		// Loop trough the custom language files
		foreach( $customLangFiles as $langFile )
		{
			// Is it a PHP file?
			if( substr( $langFile, -3, 3 ) == 'php' && $langFile != 'lang_email_content.php' )
			{
				// Then we shall add this file to the array
				$this->langArray['customLang'][ $langFile ] = $langFile;
				
			}
		}
		
		// Loop trough the default language directory
		foreach( $defaultLangFiles as $langFile )
		{
			if( substr( $langFile, -3, 3 ) == 'php' && $langFile != 'lang_email_content.php' )
			{
				// Does the file exist in the default language directory?
				if( isset( $this->langArray['customLang'][ $langFile ] ) )
				{
					// Then we shall add this file to the array
					$this->langArray['defaultLang'][ $langFile ] = $langFile;
				}
				else
				{
					// File doesn't exsist in the default lang directory, we shall copy it.
					if( copy( $this->defaultLangDir . '/' . $langFile, $this->customLangDir . '/' . $langFile ) !== FALSE )
					{
						$this->langArray['movedFiles'][] = $langFile;
					}
					else
					{	
						$this->langArray['error'][] = "Something went wrong during copying of '{$this->defaultLangDir}/{$langFile}'. Recheck the CHMOD of the folders. It should be either 0755 or 0777.";
					}
					
				}
			}
		}
	}
	
	//-----------------------------------------
	// Comparing the files
	//-----------------------------------------
	
	function compareFiles()
	{
		if( $this->langArray['defaultLang'] && is_array( $this->langArray['defaultLang'] ) )
		{
			foreach( $this->langArray['defaultLang'] as $defaultLang )
			{
				// Is this a file we want to compare?
				if( isset( $this->langArray['customLang'][ $defaultLang ] ) )
				{
					// Include both files for comparassion
					include( $this->defaultLangDir . '/' . $defaultLang );
					$defaultTmp = $lang;
					unset( $lang );
					
					include( $this->customLangDir . '/' . $defaultLang );
					$customTmp = $lang;

					
					// Are they different?
					if( count( array_diff_key( $defaultTmp, $customTmp ) ) > 0 ) 
					{
						$this->diffArray[ $defaultLang ] = array_diff_key( $defaultTmp, $customTmp );
					}
					else
					{
						// No, they aren't
						continue;
					}
								
					unset( $defaulTmp, $customTmp, $lang );
				}
			}
		}
	}
	
	//-----------------------------------------
	// Print all the differences
	//-----------------------------------------
	
	function printComparasionPage()
	{
		// Did we move some files?
		if( count( $this->langArray['movedFiles'] ) > 0 )
		{
			$output .= "<h3>The following files where copied from the default language folder, to the custom language folder.</h3><br />";
			$output .= "<table align='center' border='1' width='75%'>
							<tr>
								<th style='text-align:center'>From</th>
								<th style='text-align:center'>To</th>
							</tr>";
			
			foreach( $this->langArray['movedFiles'] as $file )
			{
				$output .= "<tr>
								<td style='text-align:center'>{$this->defaultLangDir}/{$file}</td>
								<td style='text-align:center'>{$this->customLangDir}/{$file}</td>
							</tr>";
			}
			$output .= "</table>";
		}
		
		// Did we have some errors too?
		if( count( $this->langArray['error'] ) > 0 )
		{
			$output .= "<h3>We got these error(s) while attempting to copy missing language files.</h3><br />";
			
			foreach( $this->langArray['error'] as $error )
			{
				$output .= $error . "<br />";
			}
		}
		
		//Print out the differencies
		if( count( $this->diffArray ) > 0 )
		{
			$output .= '<h3>The following entries where missing from one of your custom language files</h3><br />
			To fix these errors, simply open the file, and paste the content just below "<strong>$lang = array (</strong>"<br /><br /><br />';

			$i = 0;
			$filenames =  array_keys( $this->diffArray );
			
			foreach( $this->diffArray as $file )
			{
				$toTextArea = "";
				$output .=  "<table width='60%' border='0' cellpadding='5' align='center'>\n\r\t<tr>\n\r\t\t<td align='right'>In file: {$this->customLangDir}/{$filenames[ $i ]}<br /></td>";
				
				foreach( $file as $arrayKey => $value )
				{	
					$toTextArea .= "'{$arrayKey}' => \"{$value}\",\n\r";
				}
				
				$output .= "<td width='50%'><textarea rows='10' cols='60'>{$toTextArea}</textarea></td></tr></table><br /><hr /><br /><br />";

				$i++;
			}
			
;		}
		else
		{
			$output .= 'All of you lang files are "up-to-date"';
		}

		$output = str_replace( '<br />', "<br />\n\r", $output );
		
		$copyright = 'You may not redistribute this tool under no circumstance without my permission!<br />
		<a href="http://www.invisionmodding.com/index.php?showuser=5097" target="_blank">Martin Aronsen</a> &copy; 2008';
		
		$template = $this->mainTemplate();
		$template = str_replace( '<!--CONTENT-->', $output, $template );
		$template = str_replace( '<!--COPYRIGHT-->', $copyright, $template );
		
		
		echo $template;
	}
	
	//-----------------------------------------
	// A function holding the main template
	//-----------------------------------------
	
	function mainTemplate()
	{
		return "<html>
	<head>
		<title>[MA23] Language File Comparison Tool</title>
		<style type='text/css'>
		body
		{
			color: #FFF;
			background-color: #123456;
		}
		.content
		{
			text-align: center;
		}
		a
		{
			text-decoration: underline;
			color: #AAA;
		}
			
		</style>
	</head>
	<body>
		<div class='content'>
			<!--CONTENT-->
			<!--COPYRIGHT-->
		</div>
	</body>
	</html>";
	}
}

// Initiate the class
$compareLangFiles = new compareLangFiles;

// Change the path to your custom language folder
$compareLangFiles->customLangDir = CUSTOM_LANG_DIR;

// In most cases, this should be left untouched
$compareLangFiles->defaultLangDir = DEFAULT_LANG_DIR;

// Scan trough the folders, and create an array of all the files
$compareLangFiles->scanDirs();

// Compare the files
$compareLangFiles->compareFiles();

// Print out the result page
$compareLangFiles->printComparasionPage();

?>


#9 Michael

Michael

    See code 431.322.12 of the Internet Privacy Act

  • Modders
  • PipPipPipPipPipPipPipPipPipPip
  • 22,042 posts
  • Location:Columbus, OH
  • Real Name:Michael McCune
  • IPB Version:v3.1.x
Contributor

Posted 11 September 2008 - 10:03 PM

Fixed two parse errors.
Michael McCune - IPS Marketplace Moderator

My Stuff: My Forum · My Resources · My Tutorials
Contact Me: Email · Facebook · Twitter

#10 ilsaggio

ilsaggio

    Advanced Member

  • Banned
  • PipPipPipPip
  • 55 posts
  • IPB Version:v2.3.x

Posted 16 September 2008 - 09:49 PM

View PostTrialga, on Sep 11 2008, 05:01 PM, said:

m4rtin, to save you some time, if you are going to change the scandir area to make it PHP 4 compatible, you can use the below code ;)

if (is_dir($yourdir))
{
	$dir = opendir($yourdir);
	
	while ($d = readdir($dir))
	{
		// do what you need to do here
		// $d is a file resource
	}
	
	closedir($dir);
}
i heve 4.4.7 php
where i must put this code?

#11 Martin

Martin

    But but, it's not only only!

  • Management
  • PipPipPipPipPipPipPipPipPipPip
  • 7,081 posts
  • Location:Hammerfest, Norway
  • Real Name:Martin Aronsen
  • IPB Version:v3.2.x
Contributor

Posted 16 September 2008 - 10:17 PM

Use the code I posted two posts above yours. Michael have tested it, and fixed the two errors there were.

#12 ilsaggio

ilsaggio

    Advanced Member

  • Banned
  • PipPipPipPip
  • 55 posts
  • IPB Version:v2.3.x

Posted 19 September 2008 - 10:39 AM

so i don't use this code?
new version don't work ;)

#13 Martin

Martin

    But but, it's not only only!

  • Management
  • PipPipPipPipPipPipPipPipPipPip
  • 7,081 posts
  • Location:Hammerfest, Norway
  • Real Name:Martin Aronsen
  • IPB Version:v3.2.x
Contributor

Posted 19 September 2008 - 11:53 AM

What kind of errors are you getting?

#14 ilsaggio

ilsaggio

    Advanced Member

  • Banned
  • PipPipPipPip
  • 55 posts
  • IPB Version:v2.3.x

Posted 20 September 2008 - 11:08 PM

I do not understand, if not edit the file. php
define( 'CUSTOM_LANG_DIR', 'cache/lang_cache/norsk-beta' );

Quote

Warning: copy(cache/lang_cache/norsk-beta/acp_lang_acpperms.php) [function.copy]: failed to open stream: No such file or directory in /web/htdocs/www.consoleclan.org/home/forum/langdiff.php on line 121

Warning: copy(cache/lang_cache/norsk-beta/acp_lang_gallery_albums.php) [function.copy]: failed to open stream: No such file or directory in /web/htdocs/www.consoleclan.org/home/forum/langdiff.php on line 121

Warning: copy(cache/lang_cache/norsk-beta/acp_lang_gallery_cats.php) [function.copy]: failed to open stream: No such file or directory in /web/htdocs/www.consoleclan.org/home/forum/langdiff.php on line 121
etc...


if i edit file .php
define( 'CUSTOM_LANG_DIR', 'cache/lang_cache/34' );
(34 is my italian folder)

Quote

Fatal error: Call to undefined function: array_diff_key() in /web/htdocs/www.consoleclan.org/home/forum/langdiff.php on line 158


...i try now...and work...
;)

Edited by ilsaggio, 20 September 2008 - 11:27 PM.


#15 Martin

Martin

    But but, it's not only only!

  • Management
  • PipPipPipPipPipPipPipPipPipPip
  • 7,081 posts
  • Location:Hammerfest, Norway
  • Real Name:Martin Aronsen
  • IPB Version:v3.2.x
Contributor

Posted 20 September 2008 - 11:14 PM

You're not using the latest version. Re-download the archive, and upload langdiff.php. Make sure the file overwrites the existing one.

#16 ilsaggio

ilsaggio

    Advanced Member

  • Banned
  • PipPipPipPip
  • 55 posts
  • IPB Version:v2.3.x

Posted 21 September 2008 - 12:12 PM

is the new version...download last nigth

.. is strange if the folder contains files of the script generates an error, however if I create another empty folder with the same name, the script works but I have all files in English language...
?

that makes files in English is normal since the empty folder, but I do not understand error if the folder contains files

Quote

Fatal error: Call to undefined function: array_diff_key() in /web/htdocs/www.consoleclan.org/home/forum/langdiff.php on line 158

Edited by ilsaggio, 24 September 2008 - 07:10 PM.


#17 Martin

Martin

    But but, it's not only only!

  • Management
  • PipPipPipPipPipPipPipPipPipPip
  • 7,081 posts
  • Location:Hammerfest, Norway
  • Real Name:Martin Aronsen
  • IPB Version:v3.2.x
Contributor

Posted 21 September 2008 - 12:30 PM

Looks like array_diff_key was introduced in PHP in v5.1.0.

And that makes this tool PHP5 only.

#18 ilsaggio

ilsaggio

    Advanced Member

  • Banned
  • PipPipPipPip
  • 55 posts
  • IPB Version:v2.3.x

Posted 21 September 2008 - 08:58 PM

Quote

What's new?
v1.1 - Made it compatible with PHP4. If you use PHP5, no needs to worry.

?

#19 Martin

Martin

    But but, it's not only only!

  • Management
  • PipPipPipPipPipPipPipPipPipPip
  • 7,081 posts
  • Location:Hammerfest, Norway
  • Real Name:Martin Aronsen
  • IPB Version:v3.2.x
Contributor

Posted 21 September 2008 - 09:58 PM

I wasn't aware that that function didn't exist in PHP4. But you should still ask you're host if they can upgrade to PHP5, as PHP4 isn't supported by PHP anymore, nor by IPS on the next major release.

#20 MindTooth

MindTooth

    Member

  • Members
  • PipPipPip
  • 26 posts
  • Location:Vinstra, NORWAY
  • Real Name:Birger J. Nordølum
  • IPB Version:v2.3.x

Posted 19 October 2008 - 09:37 PM

I am getting this:

Quote

Something went wrong during copying of 'cache/lang_cache/en/acp_lang_acpperms.php'. Recheck the CHMOD of the folders. It should be either 0755 or 0777.
+++
I have tryed them both to 766 and 777. Still not getting the messages to disappear.

Birger ;)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users