#MYF-2058 Add domain support for tsmarty2c.php for smarty templates#1
Conversation
muse-monotype
left a comment
There was a problem hiding this comment.
Same functionality can be achieved with just minimal code changes to the original code.
See inline comment.
| // Defining global value of $domain | ||
| global $domain; | ||
| $domain = ''; | ||
|
|
|
|
||
| // rips gettext strings from $file and prints them in C format | ||
| function do_file($outfile, $file) { | ||
| global $domain; |
There was a problem hiding this comment.
Not needed. Remove.
| PREG_OFFSET_CAPTURE | ||
| ); | ||
|
|
||
| $result_msgdomain = array(); //msgdomain -> msgid based content |
There was a problem hiding this comment.
Not needed. Remove.
| $result_msgctxt = array(); //msgctxt -> msgid based content | ||
| $result_msgid = array(); //only msgid based content | ||
| for ($i = 0; $i < count($matches[0]); $i++) { | ||
| $msg_domain = null; |
There was a problem hiding this comment.
Not needed. Remove.
| if ($msg_domain && empty($result_msgdomain[$msg_domain])) { | ||
| $result_msgdomain[$msg_domain] = array(); | ||
| } | ||
|
|
There was a problem hiding this comment.
Not needed. Revert.
| } | ||
| echo "\n"; | ||
| } | ||
| } |
There was a problem hiding this comment.
Not needed. Revert.
| continue; | ||
| }elseif($domain != '' && $match[1] == $domain){ // Only pick strings where domain matches with domain argument provided | ||
| $msg_domain = $match[1]; | ||
| } |
There was a problem hiding this comment.
Rewrite like this:
if (defined('DOMAIN')) {
if (preg_match('/domain\s*=\s*["\']?\s*(.[^\"\']*)\s*["\']?/', $matches[2][$i][0], $match)) {
if($match[1] != DOMAIN) {
continue; // Skip strings with domain, if not matching domain to extract
}
} elseif (DOMAIN != '') {
continue; // Skip strings without domain, if domain to extract is not default/empty
}
}
| // remove -d domain from $argv. | ||
| if (isset($opt['d']) && trim($opt['d']) != '-o') { | ||
| $domain = trim($opt['d']); | ||
| foreach ($argv as $i => $v) { |
There was a problem hiding this comment.
&& trim($opt['d']) != '-o' not needed when -d is defined as an optional param
Use define instead of global variable
define('DOMAIN', trim($opt['d']));
| define('PROGRAM', basename(array_shift($argv))); | ||
| define('TMPDIR', sys_get_temp_dir()); | ||
| $opt = getopt('o:'); | ||
| $opt = getopt('d:o:'); |
There was a problem hiding this comment.
Make -d an optional param (d::) to support empty/default domain with -d or custom domain with -d=domain
|
|
||
| unset($argv[$i]); | ||
| unset($argv[$i + 1]); | ||
| break; |
There was a problem hiding this comment.
Only unset($argv[$i + 1]) when trim($opt['d']) != ''
No description provided.