get_strings.php 3.42 KB
Newer Older
1
<?php
changi67's avatar
changi67 committed
2 3 4
/**
 * @package tikiwiki
 */
5
// (c) Copyright 2002-2016 by authors of the Tiki Wiki CMS Groupware Project
6
//
7 8
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
changi67's avatar
changi67 committed
9
// $Id$
10

11
/**
12
 * Update lang/xx/language.php files
13
 *
14 15 16 17 18 19
 * Examples:
 * 		- http://localhost/pathToTiki/get_strings.php -> update all language.php files
 * 		- http://localhost/pathToTiki/get_strings.php?lang=fr -> update just lang/fr/language.php file
 * 		- http://localhost/pathToTiki/get_strings.php?lang[]=fr&lang[]=pt-br&outputFiles -> update both French
 * 		  and Brazilian Portuguese language.php files and for each string add a line with
 * 		  the file where it was found.
20
 *
21 22 23 24
 * Command line examples:
 * 		- php get_strings.php
 * 		- php get_strings.php lang=pt-br outputFiles=true
 * 		- php get_strings.php baseDir=lib/ excludeDirs=lib/core/Zend,lib/captcha includeFiles=captchalib.php,index.php fileName=language_r.php
25 26
 *
 * Note: baseDir and fileName parameters are available in command line mode only
27 28 29
 *
 *
 * If you want to know the translation progression for your language, just visit : http://i18n.tiki.org/status
30
 * which is made with http://tikiwiki.svn.sourceforge.net/viewvc/tikiwiki/trunk/doc/devtools/get_translation_percentage.php?view=markup
31
 *
32
 */
33

34
if (php_sapi_name() != 'cli') {
35
	require_once('tiki-setup.php');
36
	$access->check_permission('tiki_p_admin');
37
}
38

39
require_once('lib/init/initlib.php');
40
require_once('lib/setup/timer.class.php');
41

42 43
$timer = new timer();
$timer->start();
44

45
$options = array();
redflo's avatar
redflo committed
46

47
$request = new Tiki_Request();
48

49 50
if ($request->hasProperty('lang')) {
	$options['lang'] = $request->getProperty('lang');
51
}
52

53 54
if ($request->hasProperty('outputFiles')) {
	$options['outputFiles'] = $request->getProperty('outputFiles');
55
}
56

57
$excludeDirs = array(
58
	'dump' , 'img', 'lang',
59
	 'vendor', 'vendor_extra',
marclaporte's avatar
marclaporte committed
60 61
	 'lib/test',	'temp',
	'temp/cache',	'templates_c',
62
);
63

64 65 66
$includeFiles = array(
	'./lang/langmapping.php', './img/flags/flagnames.php'
);
67

68 69 70 71
// command-line only options
if (php_sapi_name() == 'cli') {
	if ($request->hasProperty('baseDir')) {
		$options['baseDir'] = $request->getProperty('baseDir');
72

73 74 75
		// when a custom base dir is set, default $includeFiles and $excludeDirs are not used
		$includeFiles = array();
		$excludeDirs = array();
76
	}
77

78 79
	if ($request->hasProperty('excludeDirs')) {
		$excludeDirs = explode(',', $request->getProperty('excludeDirs'));
80
	}
81

82 83
	if ($request->hasProperty('includeFiles')) {
		$includeFiles = explode(',', $request->getProperty('includeFiles'));
84
	}
85

86 87
	if ($request->hasProperty('fileName')) {
		$options['fileName'] = $request->getProperty('fileName');
88
	}
89
}
90

91
$getStrings = new Language_GetStrings(new Language_CollectFiles, new Language_WriteFile_Factory, $options);
92

93 94
$getStrings->addFileType(new Language_FileType_Php);
$getStrings->addFileType(new Language_FileType_Tpl);
95

96
// skip the following directories
97
$getStrings->collectFiles->setExcludeDirs($excludeDirs);
98

99 100
// manually add the following files from skipped directories
$getStrings->collectFiles->setIncludeFiles($includeFiles);
101

102
echo formatOutput("Languages: " . implode(' ', $getStrings->getLanguages()) . "\n");
103

104
$getStrings->run();
105

106
echo formatOutput("\nTotal time spent: " . $timer->stop() . " seconds\n");
107

108 109 110 111
/**
 * @param $string
 * @return string
 */
112 113 114 115 116 117
function formatOutput($string)
{
	if (php_sapi_name() == 'cli') {
		return $string;
	} else {
		return nl2br($string);
118
	}
119
}