function Write()
 {
     $locale = apply_filters('plugin_locale', get_locale(), 'binary-mlm-pro');
     $file = MLM_PLUGIN_DIR . "/languages/binary-mlm-pro-{$locale}.po";
     $fp = fopen($file, "w+") or die("can't open file");
     $data = stripslashes($_POST['newcontent']);
     $fff = fwrite($fp, $data);
     fclose($fp);
     phpmo_convert(MLM_PLUGIN_DIR . "/languages/binary-mlm-pro-{$locale}.po", MLM_PLUGIN_DIR . "/languages/binary-mlm-pro-{$locale}.mo");
 }
Beispiel #2
0
function generate_translations()
{
    global $languages;
    //$msgids = get_existing_msgids();
    $translations = get_translations_array();
    require APPROOT . "translate" . DIRECTORY_SEPARATOR . 'php-mo.php';
    foreach ($languages as $lkey => $language) {
        $path = APPROOT . "translate" . DIRECTORY_SEPARATOR . "translated\\php\\" . $language . "\\LC_MESSAGES" . DIRECTORY_SEPARATOR;
        $pofile = $path . $language . "_openevsys.po";
        mkdir($path, 0777, true);
        $fh = fopen($pofile, 'w+');
        $jsfile = APPROOT . "translate" . DIRECTORY_SEPARATOR . "translated\\js" . DIRECTORY_SEPARATOR . $language . ".json";
        $jsfh = fopen($jsfile, 'w+');
        fwrite($jsfh, "{\n");
        $jsonArray = array();
        foreach ($translations as $key => $transArray) {
            $origKey = $key;
            $key = addslashes($key);
            if ($transArray[$language]) {
                $value = $transArray[$language];
            } else {
                $value = $language;
            }
            $value = str_replace('"', '\\"', $value);
            fwrite($fh, "#: ----\n");
            fwrite($fh, "msgid \"{$key}\"\n");
            fwrite($fh, "msgstr \"{$value}\"\n");
            //fwrite($jsfh,"\"$key\": \"$value\",\n");
            $jsonArray[] = "\"{$origKey}\": \"{$value}\"";
            //$value;
        }
        fclose($fh);
        phpmo_convert($pofile, $path . "openevsys.mo");
        fwrite($jsfh, implode(",\n", $jsonArray));
        fwrite($jsfh, "\n}");
        fclose($jsfh);
    }
}
Beispiel #3
0
if (!file_exists($input_file) || !is_file($input_file)) {
    echo sprintf("No file %s exists\n", $input_file);
    die;
}
if (file_exists($output_file) && !is_writable($output_file)) {
    echo sprintf("Unable to write to file %s\n", $output_file);
    die;
}
$ini_values = parse_ini_file($input_file);
$pot_output = ['msgid ""
msgstr ""
"Project-Id-Version: Gantry 5\\n"
"Report-Msgid-Bugs-To: \\n"
"POT-Creation-Date: ' . date('Y-m-d H:i:sO') . '\\n"
"PO-Revision-Date: ' . date('Y-m-d H:i:sO') . '\\n"
"Last-Translator: Gantry 5 Team\\n"
"Language-Team: Gantry 5 Team\\n"
"Language: English\\n"
"MIME-Version: 1.0\\n"
"Content-Type: text/plain; charset=UTF-8\\n"
"Content-Transfer-Encoding: 8bit\\n"
"X-Poedit-KeywordsList: __;_e\\n"
"X-Poedit-Basepath: .\\n"
"X-Poedit-SearchPath-0: ..\\n"'];
foreach ($ini_values as $msgid => $msgstr) {
    $pot_output[] = sprintf('msgid "%s"', $msgid) . "\n" . sprintf('msgstr "%s"', $msgstr);
}
file_put_contents($output_file, implode("\n\n", $pot_output));
if ($compile) {
    phpmo_convert($output_file, false);
}
Beispiel #4
0
    /**
     * saves a translation
     * @param  string $language          
     * @param  array $translation_array 
     * @param  array $data_translated   
     * @return bool                    
     */
    public function save_translation($language, $translation_array, $data_translated)
    {
        //.po to .mo script
        require_once Kohana::find_file('vendor', 'php-mo/php-mo', 'php');
        //we save always in the custom file
        $mo_translation = i18n::get_language_custom_path($language);
        //changing the translation_array with the posted values
        foreach ($data_translated as $key => $value) {
            if (isset($translation_array[$key]['translated'])) {
                $translation_array[$key]['translated'] = $value;
            }
        }
        //let's generate a proper .po file for the mo converter
        $out = '';
        foreach ($translation_array as $key => $values) {
            list($id, $original, $translated) = array_values($values);
            if ($translated != '') {
                //only adding translated items
                $out .= '#: String ' . $key . PHP_EOL;
                $out .= 'msgid "' . $original . '"' . PHP_EOL;
                $out .= 'msgstr "' . $translated . '"' . PHP_EOL;
                $out .= PHP_EOL;
            }
        }
        //write the generated .po to file
        if (File::write($mo_translation, $out) === FALSE) {
            return FALSE;
        }
        //generate the .mo from the .po file
        phpmo_convert($mo_translation);
        //we regenerate the file again to be poedit friendly
        $out = 'msgid ""
msgstr ""
"Project-Id-Version: ' . Core::VERSION . '\\n"
"POT-Creation-Date: ' . Date::unix2mysql() . '\\n"
"PO-Revision-Date: ' . Date::unix2mysql() . '\\n"
"Last-Translator: ' . $this->user->name . ' <' . $this->user->email . '>\\n"
"Language-Team: en\\n"
"Language: ' . strtolower(substr($language, 0, 2)) . '\\n"
"MIME-Version: 1.0\\n"
"Content-Type: text/plain; charset=' . i18n::$charset . '\\n"
"Content-Transfer-Encoding: 8bit\\n"
"X-Generator: Open Classifieds ' . Core::VERSION . '\\n"' . PHP_EOL . PHP_EOL;
        foreach ($translation_array as $key => $values) {
            list($id, $original, $translated) = array_values($values);
            //only adding translated items
            $out .= '#: String ' . $key . PHP_EOL;
            $out .= 'msgid "' . $original . '"' . PHP_EOL;
            $out .= 'msgstr "' . $translated . '"' . PHP_EOL;
            $out .= PHP_EOL;
        }
        //write the generated .po to file
        file_put_contents($mo_translation, $out, LOCK_EX);
        return TRUE;
    }
 /**
  * Convert po-file to mo-file
  * @param string $url - url to file
  * @return boolean
  */
 public function convertToMO($url = '')
 {
     require_once realpath(dirname(__FILE__) . '/..') . '/lib/php-mo.php';
     if ($url) {
         return \phpmo_convert($url);
     }
 }
<?php

// This utility can be used to convert all po files to mo files
$dir = getcwd();
$files = scandir($dir);
include dirname(__FILE__) . '/../utils/pho-mo.php';
foreach ($files as $key => $value) {
    if (strpos($value, '.po') !== false && strpos($value, 'tmp') === false) {
        // Cleaning up Drupal PO file
        $fh = fopen($value, 'r');
        $tmp = 'tmp-' . $value;
        $tmp_fh = fopen($tmp, 'a');
        # For some reason does not like to convert successfully unless the msgid is preceeded by #\n - not sure why
        while (($line = fgets($fh, 65536)) !== false) {
            if (strpos($line, 'msgid') !== false && $last_line != '#') {
                $fwrite = fwrite($tmp_fh, "#\n");
            }
            $fwrite = fwrite($tmp_fh, $line);
            $last_line = $line;
        }
        fclose($fh);
        $new_mo = str_replace('.po', '.mo', $value);
        // Converting
        if (phpmo_convert($tmp, $new_mo)) {
            echo "Converted {$value}\n";
        } else {
            echo "Failed to convert {$value}\n";
        }
        unlink($tmp);
    }
}
<?php

//error_reporting(E_ALL | E_STRICT);
require '../admin/include/po-mo_converter/php-mo.php';
echo "Changing death [&dagger;] symbol (&amp;#134; or &amp;dagger;) to eternity [&infin;] symbol (&amp;infin;) in all language files<br><br>";
$dh = opendir("./");
while (false !== ($filename = readdir($dh))) {
    if (is_dir($filename) and $filename != ".." and $filename != '.' and strlen($filename) == 2) {
        $str = file_get_contents($filename . "/" . $filename . ".po");
        // here are the replace strings
        // anyone who wants to batch-change other or additional values can add them here
        $str = str_replace('msgstr "&#134;"', 'msgstr "&infin;"', $str);
        $str = str_replace('msgstr "&dagger;"', 'msgstr "&infin;"', $str);
        file_put_contents($filename . "/" . $filename . ".po", $str);
        if (phpmo_convert($filename . "/" . $filename . ".po") === TRUE) {
            echo 'The ' . $filename . '.mo file was succesfully saved!<br>';
        } else {
            echo 'ERROR: the ' . $filename . '.mo file IS NOT saved!<br>';
        }
    }
}
$groupM = new groupManager();
// TODO - $user = new user($_SESSION['USER_ID']);
// TODO - if(!isset($user->groupIdArray)||!in_array($groupM->getId('admins'),$user->groupIdArray)){if($m!='j'){include('plugins/core/403.php');exit(403);}}
// ------------------------------------------------------------------- //
include 'lib/getTextCompiler/php-mo.php';
// Generate the locale directories
$q0 = get_link()->prepare("SELECT \n\t\t\t\t\t\t\t\t\tloc.id AS ID,\n\t\t\t\t\t\t\t\t\tloc.short_name AS SHORT_NAME,\n\t\t\t\t\t\t\t\t\tloc.long_name AS LONG_NAME,\n\t\t\t\t\t\t\t\t\tloc.flag_path AS FLAG_PATH,\n\t\t\t\t\t\t\t\t\tloc.created_date AS CREATED_DATE,\n\t\t\t\t\t\t\t\t\tloc.created_id AS CREATED_ID,\n\t\t\t\t\t\t\t\t\tloc.edited_date AS EDITED_DATE,\n\t\t\t\t\t\t\t\t\tloc.edited_id AS EDITED_ID,\n\t\t\t\t\t\t\t\t\tloc.deleted_date AS DELETED_DATE,\n\t\t\t\t\t\t\t\t\tloc.deleted_id AS DELETED_ID\n\t\t\t\t\t\t\t\tFROM \n\t\t\t\t\t\t\t\t" . get_ini('BDD_PREFIX') . "core_locale loc\n\t\t\t\t\t\t\t\tWHERE \n\t\t\t\t\t\t\t\tloc.deleted_date=0\n\t\t\t\t\t\t\t\tORDER BY loc.long_name ASC");
$q0->execute();
while ($r0 = $q0->fetch(PDO::FETCH_OBJ)) {
    if (!is_dir('locale/' . $r0->SHORT_NAME)) {
        mkdir('locale/' . $r0->SHORT_NAME);
    }
    if (!is_dir('locale/' . $r0->SHORT_NAME . '/LC_MESSAGES')) {
        mkdir('locale/' . $r0->SHORT_NAME . '/LC_MESSAGES');
    }
    if (is_file('locale/' . $r0->SHORT_NAME . '/LC_MESSAGES/lang.po')) {
        unlink('locale/' . $r0->SHORT_NAME . '/LC_MESSAGES/lang.po');
    }
    if (is_file('locale/' . $r0->SHORT_NAME . '/LC_MESSAGES/lang.mo')) {
        unlink('locale/' . $r0->SHORT_NAME . '/LC_MESSAGES/lang.mo');
    }
}
// Generate po files
$q0 = get_link()->prepare("SELECT \n\t\t\t\t\t\t\t\t\ttrans.id AS ID,\n\t\t\t\t\t\t\t\t\ttrans.id_plugin AS ID_PLUGIN,\n\t\t\t\t\t\t\t\t\ttrans.id_locale AS ID_LOCALE,\n\t\t\t\t\t\t\t\t\tpg.name AS PLUGINNAME,\n\t\t\t\t\t\t\t\t\tloc.short_name AS SHORT_NAME,\n\t\t\t\t\t\t\t\t\ttrans.index_translation AS INDEX_TRANSLATION,\n\t\t\t\t\t\t\t\t\ttrans.translation AS TRANSLATION,\n\t\t\t\t\t\t\t\t\ttrans.comment AS COMMENT,\n\t\t\t\t\t\t\t\t\ttrans.created_date AS CREATED_DATE,\n\t\t\t\t\t\t\t\t\ttrans.created_id AS CREATED_ID,\n\t\t\t\t\t\t\t\t\ttrans.edited_date AS EDITED_DATE,\n\t\t\t\t\t\t\t\t\ttrans.edited_id AS EDITED_ID,\n\t\t\t\t\t\t\t\t\ttrans.deleted_date AS DELETED_DATE,\n\t\t\t\t\t\t\t\t\ttrans.deleted_id AS DELETED_ID\n\t\t\t\t\t\t\t\tFROM \n\t\t\t\t\t\t\t\t" . get_ini('BDD_PREFIX') . "core_translation trans ,\n\t\t\t\t\t\t\t\t" . get_ini('BDD_PREFIX') . "core_plugins pg ,\n\t\t\t\t\t\t\t\t" . get_ini('BDD_PREFIX') . "core_locale loc\n\t\t\t\t\t\t\t\tWHERE \n\t\t\t\t\t\t\t\ttrans.id_plugin=pg.id AND\n\t\t\t\t\t\t\t\ttrans.id_locale=loc.id AND\n\t\t\t\t\t\t\t\tloc.deleted_date=0 AND\n\t\t\t\t\t\t\t\tpg.deleted_date=0 AND\n\t\t\t\t\t\t\t\ttrans.deleted_date=0\n\t\t\t\t\t\t\t\tORDER BY loc.short_name ASC,trans.index_translation ASC,pg.name ASC");
$q0->execute();
while ($r0 = $q0->fetch(PDO::FETCH_OBJ)) {
    file_put_contents('locale/' . $r0->SHORT_NAME . '/LC_MESSAGES/lang.po', '#: ' . $r0->COMMENT . "\n" . 'msgid "#' . $r0->PLUGINNAME . '#_#' . $r0->INDEX_TRANSLATION . '#"' . "\n" . 'msgstr "' . $r0->TRANSLATION . '"' . "\n\n", FILE_APPEND);
}
foreach (glob("locale/*/*/*.po") as $poFileName) {
    phpmo_convert($poFileName, str_replace('.po', '.mo', $poFileName));
}
    $key_offsets = array();
    $value_offsets = array();
    // calculate
    foreach ($offsets as $v) {
        list($o1, $l1, $o2, $l2) = $v;
        $key_offsets[] = $l1;
        $key_offsets[] = $o1 + $key_start;
        $value_offsets[] = $l2;
        $value_offsets[] = $o2 + $value_start;
    }
    $offsets = array_merge($key_offsets, $value_offsets);
    // write header
    $mo .= pack('Iiiiiii', 0.0, 0, sizeof($hash), 7 * 4, 7 * 4 + sizeof($hash) * 8, 0, $key_start);
    // offsets
    foreach ($offsets as $offset) {
        $mo .= pack('i', $offset);
    }
    // ids
    $mo .= $ids;
    // strings
    $mo .= $strings;
    file_put_contents($out, $mo);
}
$options = getopt('i:o:');
if (!empty($options)) {
    $input = realpath($options['i']);
    $output = isset($options['o']) ? realpath($options['o']) : false;
    if (file_exists($input)) {
        phpmo_convert($input, $output);
    }
}
                } else {
                    // no msgstr such as after #~ remarks
                    fwrite($handle_write, "\n");
                }
            }
        }
        $message = __('Saved') . ' ';
        $message .= __('Language') . ': ' . $file;
        echo $message;
    } else {
        echo "Saving failed!";
    }
    fclose($handle_write);
    // *** Convert .po file into .mo file! ***
    require CMS_ROOTPATH . 'admin/include/po-mo_converter/php-mo.php';
    if (phpmo_convert($file)) {
        //echo 'The .mo file is succesfully saved!';
    } else {
        echo '<br>ERROR: the .mo file IS NOT saved!<br>';
    }
}
$line_array = array();
$handle = @fopen($file, "r");
if ($handle) {
    $count = 0;
    $msgid = 0;
    $msgstr = 0;
    $note = 0;
    $line_array = array();
    while (($buffer = fgets($handle, 4096)) !== false) {
        if (substr($buffer, 0, 5) == "msgid") {
    function form($instance)
    {
        global $WPMailjet;
        // if there are translation entries in the POST, update them
        if ($this->preg_array_key_exists('/msgstr/', $_POST)) {
            require_once dirname(__FILE__) . '/libs/php.mo-master/php-mo.php';
            foreach ($this->langs as $lang => $locale) {
                foreach ($_POST as $key => $value) {
                    if (substr($key, 0, 7) === 'msgstr-') {
                        foreach ($this->{'entries' . $lang} as $entryKey => $entryValue) {
                            if ($this->entryStrToId($entryKey) === str_replace('msgstr-' . $lang . '-', '', $key)) {
                                $this->{'entries' . $lang}[$entryKey]['msgstr'][0] = stripcslashes($_POST[$key]);
                                $this->{'poParser' . $lang}->setEntry($entryKey, $this->{'entries' . $lang}[$entryKey]);
                            }
                        }
                    }
                }
            }
            foreach ($this->langs as $lang => $locale) {
                $this->{'poParser' . $lang}->writeFile(dirname(__FILE__) . '/i18n/wp-mailjet-subscription-widget-' . $locale['locale'] . '.po');
                phpmo_convert(dirname(__FILE__) . '/i18n/wp-mailjet-subscription-widget-' . $locale['locale'] . '.po');
            }
            if (in_array(get_locale(), array('en_US', 'en_EN', ''))) {
                foreach (array('-en_US', '-en_EN', '') as $lang) {
                    $this->poParseren->writeFile(dirname(__FILE__) . '/i18n/wp-mailjet-subscription-widget' . $lang . '.po');
                    phpmo_convert(dirname(__FILE__) . '/i18n/wp-mailjet-subscription-widget' . $lang . '.po');
                }
            }
        }
        $fields = array('new_meta_name', 'new_meta_data_type');
        $langFields = array('enableTab', 'title', 'list_id', 'button_text', 'metaPropertyName1', 'metaPropertyName2', 'metaPropertyName3', 'metaProperty1', 'metaProperty2', 'metaProperty3');
        foreach ($fields as $prop) {
            ${$prop} = empty($instance[$prop]) ? '' : $instance[$prop];
        }
        foreach ($langFields as $prop) {
            foreach ($this->langs as $lang => $langProps) {
                ${$prop . $lang} = empty($instance[$prop . $lang]) ? '' : $instance[$prop . $lang];
            }
        }
        ?>
        <div class="mailjet-widget-container">
        <div class="accordion">
            <h3>Step 1 - Choose up to 3 contact properties</h3>
            <div>
                <?php 
        $contactMetaProperties = $this->getContactMetaProperties();
        if ($this->_userVersion === 3) {
            ?>
                <?php 
            if (empty($contactMetaProperties->Data)) {
                ?>
                    <div class="fontSizeSmall noProperties"><?php 
                echo sprintf('No contact properties have been defined yet. Please create one by clicking on "Add New Property" below or by logging into your Mailjet account.');
                ?>
</div>
                    <div class="fontSizeSmall yesProperties" style="display:none;"><?php 
                echo sprintf('Drag and drop up to %d contact properties from "Available contact properties" to "Selected contact properties" (besides email which is mandatory).', self::MAX_META_PROPERTIES);
                ?>
</div>
                    <div class="label yesProperties" style="display:none;">Available contact properties</div>
                <?php 
            } else {
                ?>
                    <div class="fontSizeSmall yesProperties"><?php 
                echo sprintf('Drag and drop up to %d contact properties from "Available contact properties" to "Selected contact properties" (besides email which is mandatory).', self::MAX_META_PROPERTIES);
                ?>
</div>
                    <div class="label">Available contact properties</div>
                <?php 
            }
            ?>
                <div class="sortable" <?php 
            if (empty($contactMetaProperties->Data)) {
                ?>
 style="display:none;"  <?php 
            }
            ?>
 >
                    <div>
                        <ul class="connectedSortable sortable1">
                            <?php 
            foreach ($contactMetaProperties->Data as $prop) {
                $lang = 'en';
                //foreach($this->langs as $lang => $langProps):
                ?>
                                        <?php 
                if (!in_array($prop->Name, array(${'metaPropertyName1' . $lang}, ${'metaPropertyName2' . $lang}, ${'metaPropertyName3' . $lang}))) {
                    ?>
                                            <li class="ui-state-default"><div class="cursorMoveImg"></div>&nbsp;&nbsp;&nbsp;&nbsp;<?php 
                    echo $prop->Name;
                    ?>
</li>
                                        <?php 
                }
                ?>
                                    <?php 
                //endforeach;
                ?>
                            <?php 
            }
            ?>
                        </ul>
                    </div>
                    <div>
                        <div class="label">Selected properties</div>
                        <div class="fontSizeSmall">Arrange and sort the properties you selected to determine the way they will be shown in the widget.</div>
                        <ul class="connectedSortable sortable2">
                            <li class="ui-state-disabled">Email address (mandatory)</li>
                            <?php 
            $selectedProps = array();
            foreach ($instance as $prop) {
                if (empty($prop) || in_array($prop, $selectedProps)) {
                    continue;
                }
                $lang = 'en';
                ?>
                                    <?php 
                if (in_array($prop, array(${'metaPropertyName1' . $lang}, ${'metaPropertyName2' . $lang}, ${'metaPropertyName3' . $lang}))) {
                    ?>
                                        <li class="ui-state-default"><div class="cursorMoveImg"></div>&nbsp;&nbsp;&nbsp;&nbsp;<?php 
                    echo $prop;
                    ?>
</li>
                                        <?php 
                    $selectedProps[] = $prop;
                    ?>
                                    <?php 
                }
                ?>
                            <?php 
            }
            ?>
                        </ul>
                    </div>
                </div>

                <div class="new-meta-contact-form">
                    <div class="label">Add New Property</div>
                    <div>Click on the button below to dynamically add a new contact property to your contact list and widget.</div>
                    <ul class="newPropertyBtn">
                        <li>Add a new property</li>
                    </ul>
                    <?php 
            if (isset($metaAdded)) {
                ?>
                        <div class="success">Property created. Please drag your new contact property to the Selected Properties section above.</div>
                    <?php 
            }
            ?>
                    <div class="newPropertyForm ninja">
                        <div class="new-meta-property-response"></div>
                        <div>
                            <label>Name</label><br/>
                            <input type="text" name="new_meta_name" class="new_meta_name"
                                title="Please make sure you are not using forbidden characters: , * + - / &quot; ' : [ ] ( ) > < = ; $"/>
                        </div>
                        <div>
                            <label>Contact property type</label><br/>
                            <select name="new_meta_data_type" class="new_meta_data_type">
                                <option value="str">String (ex. FirstName)</option>
                                <option value="int">Integer (ex. 90210)</option>
                                <option value="float">Decimal (ex. 6245.538)</option>
                                <option value="bool">Bool</option>
                            </select>
                        </div>
                        <p>
                            <input type="submit" name="submit" class="button new-meta-submit" value="Add"/>
                            <input name="action" type="hidden" value="mailjet_subscribe_ajax_add_meta_property"/>
                        </p>
                    </div>
                </div>
                    <?php 
        }
        ?>
                <p>
                    <input type="submit" class="next floatRight button" value="Next"/>
                </p>
            </div>

            <h3>Step 2 - Define your widget labels</h3>
            <div>
                <div class="tabs-container">
                    <ul class="tabs-menu">
                        <?php 
        foreach ($this->langs as $lang => $langProps) {
            ?>
                            <li class="<?php 
            echo $lang === 'en' ? 'current' : '';
            ?>
">
                                <a href=".tab-<?php 
            echo $lang;
            ?>
"><?php 
            echo $langProps['label'];
            ?>
</a>
                            </li>
                        <?php 
        }
        ?>
                    </ul>
                    <div class="tab">
                        <?php 
        foreach ($this->langs as $lang => $langProps) {
            ?>
                            <div class="tab-content tab-<?php 
            echo $lang;
            ?>
">
                                <div class="tabActivator<?php 
            echo $lang === 'en' ? ' ninja' : '';
            ?>
" id="<?php 
            echo $this->get_field_id('tabActivator-' . $lang);
            ?>
">
                                    <input type="checkbox" name="<?php 
            echo $this->get_field_name('enableTab' . $lang);
            ?>
"
                                           class="enable-tab enable-tab-<?php 
            echo $lang;
            ?>
" id="<?php 
            echo $this->get_field_id('enableTab' . $lang);
            ?>
"
                                           <?php 
            echo $lang === 'en' ? 'checked="checked"' : (empty(${'enableTab' . $lang}) ? '' : 'checked="checked"');
            ?>
 />
                                    <label for="<?php 
            echo $this->get_field_id('enableTab' . $lang);
            ?>
">Activate tab</label>
                                </div>
                                <!-- This element will be populated with input text fields for each selected meta property -->
                                <div class="fontSizeSmall">Please enter specific labels for your subscription widget and they
                                    will be displayed on the front end of your website.</div>
                                <?php 
            if ($this->_userVersion === 3) {
                ?>
                                    <div class="clear map-meta-properties">
                                    <?php 
                for ($i = 1; $i <= 3; $i++) {
                    ?>
                                        <div class="<?php 
                    echo $this->get_field_id('metaProperty' . $i . $lang);
                    ?>
">
                                            <label for="<?php 
                    echo $this->get_field_id('metaProperty' . $i . $lang);
                    ?>
"><?php 
                    echo esc_attr(${'metaPropertyName' . $i . $lang});
                    ?>
</label>
                                            <input type="hidden" id="<?php 
                    echo $this->get_field_id('metaPropertyName' . $i . $lang);
                    ?>
"
                                                name="<?php 
                    echo $this->get_field_name('metaPropertyName' . $i . $lang);
                    ?>
"
                                                value="<?php 
                    echo esc_attr(${'metaPropertyName' . $i . $lang});
                    ?>
" />
                                            <input class="widefat"
                                                id="<?php 
                    echo $this->get_field_id('metaProperty' . $i . $lang);
                    ?>
"
                                                name="<?php 
                    echo $this->get_field_name('metaProperty' . $i . $lang);
                    ?>
"
                                                type="text"
                                                value="<?php 
                    echo empty(${'metaProperty' . $i . $lang}) ? '' : esc_attr(${'metaProperty' . $i . $lang});
                    ?>
"
                                                size="28" />
                                        </div>
                                    <?php 
                }
                ?>
                                    </div>
                                <?php 
            }
            ?>
                                <p>
                                    <label for="<?php 
            echo $this->get_field_id('title' . $lang);
            ?>
"
                                        title="This is the title of your subscription widget which will be displayed on your website">Title:
                                        <input class="widefat" id="<?php 
            echo $this->get_field_id('title' . $lang);
            ?>
"
                                            name="<?php 
            echo $this->get_field_name('title' . $lang);
            ?>
" type="text"
                                            value="<?php 
            echo esc_attr(${'title' . $lang});
            ?>
"/>
                                    </label>
                                </p>
                                <p>
                                    <label for="<?php 
            echo $this->get_field_id('button_text' . $lang);
            ?>
"
                                        title="This will be the label of your subscription button which will be displayed on your website">Button text
                                        <input class="widefat" id="<?php 
            echo $this->get_field_id('button_text' . $lang);
            ?>
"
                                            name="<?php 
            echo $this->get_field_name('button_text' . $lang);
            ?>
" type="text"
                                            value="<?php 
            echo esc_attr(${'button_text' . $lang});
            ?>
"/>
                                    </label>
                                </p>
                                <p>
                                    <label for="<?php 
            echo $this->get_field_id('list_id' . $lang);
            ?>
"
                                        title="Please chose a contact list where all new subscribers will be added">List:
                                        <select class="widefat" <?php 
            echo isset($_POST) && count($_POST) > 0 && !is_numeric(${'list_id' . $lang}) ? 'style="border:1px solid red;' : '';
            ?>
 id="<?php 
            echo $this->get_field_id('list_id' . $lang);
            ?>
"
                                            name="<?php 
            echo $this->get_field_name('list_id' . $lang);
            ?>
">
                                            <?php 
            foreach ($this->getLists() as $list) {
                ?>
                                                <option value="<?php 
                echo $list['value'];
                ?>
"<?php 
                echo $list['value'] == esc_attr(${'list_id' . $lang}) ? ' selected="selected"' : '';
                ?>
><?php 
                echo $list['label'];
                ?>
</option>
                                            <?php 
            }
            ?>
                                        </select>
                                    </label>
                                </p>
                            </div>
                        <?php 
        }
        ?>
                    </div>
                    <p>
                        <input type="submit" class="previous button" value="Back"/>
                        <input type="submit" class="next floatRight button" value="Next"/>
                    </p>
                </div>
            </div>

            <h3>Step 3 - Customize your widget notifications</h3>
            <div>
                <div class="tabs-container">
                    <ul class="tabs-menu">
                        <?php 
        foreach ($this->langs as $lang => $langProps) {
            ?>
                            <li class="<?php 
            echo $lang === 'en' ? 'current' : '';
            ?>
">
                                <a href=".tab-<?php 
            echo $lang;
            ?>
"><?php 
            echo $langProps['label'];
            ?>
</a>
                            </li>
                        <?php 
        }
        ?>
                    </ul>
                    <div class="tab">
                        <?php 
        foreach ($this->langs as $lang => $langProps) {
            ?>
                        <div class="tab-content tab-<?php 
            echo $lang;
            ?>
">
                            <div class="mj-translations-title margin-top-bottom-10 arrow_box" id="mj-translations-title-<?php 
            echo $lang;
            ?>
">
                                <div style="display:none;">Widget notifications for this language are deactivated in previous step</div>
                                <a id="<?php 
            echo $this->get_field_id('tabLinkStep3-' . $lang);
            ?>
" href="javascript:">Customize your widget notifications</a></div>
                            <div class="mj-string-translations" id="<?php 
            echo $this->get_field_id('mj-string-translations-' . $lang);
            ?>
">
                                <?php 
            $i = 0;
            foreach ($this->{'entries' . $lang} as $msgid => $msg) {
                $id = $this->entryStrToId($msgid);
                $i++;
                if ($i === 1) {
                    ?>
                                        <h4>Errors/Website notifications</h4>
                                    <?php 
                } elseif ($i === 8) {
                    ?>
                                        <h4>Subscription confirmation mail</h4>
                                    <?php 
                }
                ?>
                                    <div class="mj-translation-entry">
                                        <h6><?php 
                echo $msgid;
                ?>
</h6>
                                            <textarea name="msgstr-<?php 
                echo $lang;
                ?>
-<?php 
                echo $id;
                ?>
" id="msgstr-<?php 
                echo $lang;
                ?>
-<?php 
                echo $id;
                ?>
"
                                                rows="5" cols="30"><?php 
                echo $msg['msgstr'][0];
                ?>
</textarea>
                                    </div>
                                <?php 
            }
            ?>
                            </div>
                        </div>
                         <?php 
        }
        ?>
                    </div>
                    <p><input type="submit" class="previous button" value="Back"/></p>
                </div>
            </div>
        </div>
        </div>
        <?php 
        if (isset($_POST) && count($_POST) > 0) {
            ?>
        <div class="mailjet_subscribe_response"><?php 
            echo 'Success! Please go to your wordpress site to see your widget in action.';
            ?>
</div>
    <?php 
        }
        $WPMailjet->addMjJsGlobalVar();
    }
                        $low_locale = join('-', $tags_locale);
                    } else {
                        $t = 'default';
                    }
                    $commands[] = "php '{$glotpress_path}/scripts/export.php' -p {$glotpress_project} -l {$low_locale} -t {$t} -o po > {$pot_git_checkout}{$relative_po_path}/{$locale}/LC_MESSAGES/{$locale}.po";
                    //$commands[] = "php '{$glotpress_path}/scripts/export.php' -p {$glotpress_project} -l {$low_locale} -t {$t} -o mo > {$pot_git_checkout}{$relative_po_path}/{$locale}/LC_MESSAGES/{$locale}.mo";
                    $po_files[] = "{$pot_git_checkout}{$relative_po_path}/{$locale}/LC_MESSAGES/{$locale}.po";
                }
            }
            closedir($dh);
        }
        $commit_message = join("\n", $commit_message);
    }
}
// Make the POs
run_commands($commands);
// Make the MOs
if (!empty($po_files) && !$dry_run) {
    require_once 'php-mo.php';
    foreach ($po_files as $po_file) {
        phpmo_convert($po_file);
    }
}
// Only commit if required
if (!$exists || $real_differences || !empty($commit_message)) {
    if (empty($commit_message)) {
        $commit_message = 'Dev Automatic translation update';
    }
    $commands = array("git commit -am '{$commit_message}'", "git push origin {$branch}");
    run_commands($commands);
}
Beispiel #13
0
 public function action_edit()
 {
     if ($this->request->param('id')) {
         $language = $this->request->param('id');
         $default = DOCROOT . 'languages/' . $language . '/LC_MESSAGES/messages.po';
         $default_mo = DOCROOT . 'languages/' . $language . '/LC_MESSAGES/messages.mo';
     } else {
         Request::current()->redirect(Route::url('oc-panel', array('controller' => 'translations')));
     }
     Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Edit Translation')));
     $this->template->title = __('Edit Translation');
     $this->template->bind('content', $content);
     $content = View::factory('oc-panel/pages/translations/edit');
     $this->template->scripts['footer'][] = 'js/oc-panel/translations.js';
     $base_translation = i18n::get_language_path();
     //pear gettext scripts
     require_once Kohana::find_file('vendor', 'GT/Gettext', 'php');
     require_once Kohana::find_file('vendor', 'GT/Gettext/PO', 'php');
     require_once Kohana::find_file('vendor', 'GT/Gettext/MO', 'php');
     //.po to .mo script
     require_once Kohana::find_file('vendor', 'php-mo/php-mo', 'php');
     //load the .po files
     $pocreator_en = new File_Gettext_PO();
     $pocreator_en->load($base_translation);
     $pocreator_default = new File_Gettext_PO();
     $pocreator_default->load($default);
     $en_array_order = $pocreator_en->strings;
     //        ksort($en_array_order,SORT_NATURAL); // since PHP 5.4
     natcasesort($en_array_order);
     // better than natsort() ??
     //watch out there's a limit of 1000 posts....we have 540...
     if ($this->request->post()) {
         foreach ($en_array_order as $key => $string) {
             $keys[] = $key;
         }
         $translations = $this->request->post('translations');
         $strings = array();
         $out = '';
         foreach ($translations as $key => $value) {
             if ($value != "") {
                 $strings[$keys[$key]] = $value;
                 $out .= '#: String ' . $key . PHP_EOL;
                 $out .= 'msgid "' . $keys[$key] . '"' . PHP_EOL;
                 $out .= 'msgstr "' . $value . '"' . PHP_EOL;
                 $out .= PHP_EOL;
             }
         }
         //write the generated .po to file
         $fp = fopen($default, 'w+');
         $read = fwrite($fp, $out);
         fclose($fp);
         $pocreator_default->strings = $strings;
         //generate the .mo from the .po file
         phpmo_convert($default);
         Alert::set(Alert::SUCCESS, $this->request->param('id') . ' ' . __('Language saved'));
         Request::current()->redirect(Route::url('oc-panel', array('controller' => 'translations', 'action' => 'edit', 'id' => $this->request->param('id'))));
     }
     $content->edit_language = $this->request->param('id');
     $content->strings_en = $en_array_order;
     $content->strings_default = $pocreator_default->strings;
 }