50 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			50 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
function extract_strings($cont)
 | 
						|
{
 | 
						|
	preg_match_all("/([A-Za-z_ ]+): (.*)/", $cont, $matches, PREG_SET_ORDER, 0);
 | 
						|
	$strings = [];
 | 
						|
	foreach ($matches as $match)
 | 
						|
	{
 | 
						|
		$strings[$match[1]] = $match[2];
 | 
						|
	}
 | 
						|
	return $strings;
 | 
						|
}
 | 
						|
 | 
						|
foreach (["bootstrapper-core", "bootstrapper-webui"] as $folder)
 | 
						|
{
 | 
						|
	$source = file_get_contents("$folder/en.cat.txt");
 | 
						|
	$source_strings = extract_strings($source);
 | 
						|
	$source_lines = explode("\n", $source);
 | 
						|
 | 
						|
	foreach (scandir("$folder") as $file)
 | 
						|
	{
 | 
						|
		if (is_file("$folder/$file") && $file != "en.cat.txt")
 | 
						|
		{
 | 
						|
			$cont = file_get_contents("$folder/$file");
 | 
						|
			$target_strings = extract_strings($cont);
 | 
						|
			$fh = fopen("$folder/$file", "wb");
 | 
						|
			foreach ($source_lines as $line)
 | 
						|
			{
 | 
						|
				if ($strings = extract_strings($line))
 | 
						|
				{
 | 
						|
					foreach ($strings as $key => $value)
 | 
						|
					{
 | 
						|
						if (array_key_exists($key, $target_strings))
 | 
						|
						{
 | 
						|
							fwrite($fh, "$key: $target_strings[$key]\n");
 | 
						|
						}
 | 
						|
						else
 | 
						|
						{
 | 
						|
							fwrite($fh, "$key: [UNTRANSLATED] $value\n");
 | 
						|
						}
 | 
						|
					}
 | 
						|
				}
 | 
						|
				else
 | 
						|
				{
 | 
						|
					fwrite($fh, $line."\n");
 | 
						|
				}
 | 
						|
			}
 | 
						|
		}
 | 
						|
	}
 | 
						|
}
 |