Skip to content

#MYF-2058 Add domain support for tsmarty2c.php for smarty templates#1

Merged
muse-monotype merged 5 commits intomasterfrom
feature/smarty-gettext-extension
May 11, 2017
Merged

#MYF-2058 Add domain support for tsmarty2c.php for smarty templates#1
muse-monotype merged 5 commits intomasterfrom
feature/smarty-gettext-extension

Conversation

@nishantweb
Copy link
Copy Markdown
Collaborator

No description provided.

Copy link
Copy Markdown
Collaborator

@muse-monotype muse-monotype left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same functionality can be achieved with just minimal code changes to the original code.

See inline comment.

Comment thread tsmarty2c.php Outdated
// Defining global value of $domain
global $domain;
$domain = '';

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No needed. Remove.

Comment thread tsmarty2c.php Outdated

// rips gettext strings from $file and prints them in C format
function do_file($outfile, $file) {
global $domain;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed. Remove.

Comment thread tsmarty2c.php Outdated
PREG_OFFSET_CAPTURE
);

$result_msgdomain = array(); //msgdomain -> msgid based content
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed. Remove.

Comment thread tsmarty2c.php Outdated
$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;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed. Remove.

Comment thread tsmarty2c.php Outdated
if ($msg_domain && empty($result_msgdomain[$msg_domain])) {
$result_msgdomain[$msg_domain] = array();
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed. Revert.

Comment thread tsmarty2c.php Outdated
}
echo "\n";
}
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed. Revert.

Comment thread tsmarty2c.php Outdated
continue;
}elseif($domain != '' && $match[1] == $domain){ // Only pick strings where domain matches with domain argument provided
$msg_domain = $match[1];
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread tsmarty2c.php Outdated
// remove -d domain from $argv.
if (isset($opt['d']) && trim($opt['d']) != '-o') {
$domain = trim($opt['d']);
foreach ($argv as $i => $v) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

&& 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']));

Comment thread tsmarty2c.php Outdated
define('PROGRAM', basename(array_shift($argv)));
define('TMPDIR', sys_get_temp_dir());
$opt = getopt('o:');
$opt = getopt('d:o:');
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make -d an optional param (d::) to support empty/default domain with -d or custom domain with -d=domain

Comment thread tsmarty2c.php Outdated

unset($argv[$i]);
unset($argv[$i + 1]);
break;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only unset($argv[$i + 1]) when trim($opt['d']) != ''

@nishantweb nishantweb changed the title #MYF-1714 Prepare string translations #MYF-2058 Add domain support for tsmarty2c.php for smarty templates May 11, 2017
@muse-monotype muse-monotype merged commit b0f5fd5 into master May 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants