<commit_before>#!/usr/bin/env php
<?php
/*
 * StatusNet - the distributed open-source microblogging tool
 * Copyright (C) 2008, 2009, StatusNet, Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

// Abort if called from a web server
if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
    print "This script must be run from the command line\n";
    exit();
}

define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));

function update_core($dir, $domain)
{
    $old = getcwd();
    chdir($dir);
    passthru(<<<END
xgettext \
    --from-code=UTF-8 \
    --default-domain=$domain \
    --output=locale/$domain.pot \
    --language=PHP \
    --add-comments=TRANS \
    --keyword="_m:1,1t" \
    --keyword="_m:1c,2,2t" \
    --keyword="_m:1,2,3t" \
    --keyword="_m:1c,2,3,4t" \
    --keyword="pgettext:1c,2" \
    --keyword="npgettext:1c,2,3" \
    actions/*.php \
    classes/*.php \
    lib/*.php \
    scripts/*.php
END
);
    chdir($old);
}

function do_update_plugin($dir, $domain)
{
    $old = getcwd();
    chdir($dir);
    if (!file_exists('locale')) {
        mkdir('locale');
    }
    $files = get_plugin_sources(".");
    $cmd = <<<END
xgettext \
    --from-code=UTF-8 \
    --default-domain=$domain \
    --output=locale/$domain.pot \
    --language=PHP \
    --add-comments=TRANS \
    --keyword='' \
    --keyword="_m:1,1t" \
    --keyword="_m:1c,2,2t" \
    --keyword="_m:1,2,3t" \
    --keyword="_m:1c,2,3,4t" \

END;
    foreach ($files as $file) {
      $cmd .= ' ' . escapeshellarg($file);
    }
    passthru($cmd);
    chdir($old);
}

function do_translatewiki_plugin($basedir, $plugin)
{
    $yamldir = "$basedir/locale/TranslateWiki";
    if (!file_exists($yamldir)) {
        mkdir($yamldir);
    }
    $outfile = "$yamldir/StatusNet-{$plugin}.yml";
    $pluginlc = strtolower( $plugin );
    $data = <<<END
---
BASIC:
  id: out-statusnet-{$pluginlc}
  label: StatusNet - {$plugin}
  description: "{{int:bw-desc-statusnet-plugin-{$pluginlc}}}"
  namespace: NS_STATUSNET
  display: out/statusnet/{$pluginlc}
  class: GettextMessageGroup

FILES:
  class: GettextFFS
  sourcePattern: %GROUPROOT%/plugins/{$plugin}/locale/%CODE%/LC_MESSAGES/{$plugin}.po
  targetPattern: plugins/{$plugin}/locale/%CODE%/LC_MESSAGES/{$plugin}.po
  codeMap:
    en-gb: en_GB
    no: nb
    pt-br: pt_BR
    zh-hans: zh_CN
    zh-hant: zh_TW

MANGLER
  class: StringMatcher
  prefix: {$pluginlc}-
  patterns:
    - "*"

END;
    file_put_contents($outfile, $data);<commit_msg>Update extension configuration file creation (doesn't work yet in translatewiki.net).<commit_after>#!/usr/bin/env php
<?php
/*
 * StatusNet - the distributed open-source microblogging tool
 * Copyright (C) 2008, 2009, StatusNet, Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

// Abort if called from a web server
if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
    print "This script must be run from the command line\n";
    exit();
}

define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));

function update_core($dir, $domain)
{
    $old = getcwd();
    chdir($dir);
    passthru(<<<END
xgettext \
    --from-code=UTF-8 \
    --default-domain=$domain \
    --output=locale/$domain.pot \
    --language=PHP \
    --add-comments=TRANS \
    --keyword="_m:1,1t" \
    --keyword="_m:1c,2,2t" \
    --keyword="_m:1,2,3t" \
    --keyword="_m:1c,2,3,4t" \
    --keyword="pgettext:1c,2" \
    --keyword="npgettext:1c,2,3" \
    actions/*.php \
    classes/*.php \
    lib/*.php \
    scripts/*.php
END
);
    chdir($old);
}

function do_update_plugin($dir, $domain)
{
    $old = getcwd();
    chdir($dir);
    if (!file_exists('locale')) {
        mkdir('locale');
    }
    $files = get_plugin_sources(".");
    $cmd = <<<END
xgettext \
    --from-code=UTF-8 \
    --default-domain=$domain \
    --output=locale/$domain.pot \
    --language=PHP \
    --add-comments=TRANS \
    --keyword='' \
    --keyword="_m:1,1t" \
    --keyword="_m:1c,2,2t" \
    --keyword="_m:1,2,3t" \
    --keyword="_m:1c,2,3,4t" \

END;
    foreach ($files as $file) {
      $cmd .= ' ' . escapeshellarg($file);
    }
    passthru($cmd);
    chdir($old);
}

function do_translatewiki_plugin($basedir, $plugin)
{
    $yamldir = "$basedir/locale/TranslateWiki";
    if (!file_exists($yamldir)) {
        mkdir($yamldir);
    }
    $outfile = "$yamldir/StatusNet-{$plugin}.yml";
    $pluginlc = strtolower( $plugin );
    $data = <<<END
---
BASIC:
  id: out-statusnet-{$pluginlc}
  label: StatusNet - {$plugin}
  namespace: NS_STATUSNET
  description: "{{int:bw-desc-statusnet-plugin}}"
  class: FileBasedMessageGroup
  display: out/statusnet/{$pluginlc}

FILES:
  class: GettextFFS
  sourcePattern: %GROUPROOT%/statusnet/plugins/{$plugin}/locale/{$plugin}.pot
  targetPattern: statusnet/plugins/{$plugin}/locale/%CODE%/LC_MESSAGES/{$plugin}.po
  codeMap:
    en-gb: en_GB
    no: nb
    pt-br: pt_BR
    zh-hans: zh_CN
    zh-hant: zh_TW

MANGLER
  class: StringMatcher
  prefix: {$pluginlc}-
  patterns:
    - "*"

END;
    file_put_contents($outfile, $data);
{'fraction_non_alphanumeric': 0.16202090592334495, 'fraction_numerical': 0.012670256572695597, 'mean_word_length': 3.029993618379068, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6695976', 'n_tokens_mistral': 2251, 'n_tokens_neox': 2211, 'n_words': 518}