*
 * @param sring $url URL
 * @return sstring API URL
 */
function apize_url($url)
{
    if (false !== strpos($url, '/api')) {
        return $url;
    }
    $host = preg_quote(parse_url($url, PHP_URL_HOST));
    return preg_replace("#^https?://{$host}#", '\\0/api', $url);
}
if (empty($argv[1])) {
    die_error('No DESTINATION_URL specified');
}
$destination_url = apize_url(rtrim($argv[1], '/'));
$destination = json_decode(file_get_contents($destination_url));
$destination_locales = array();
foreach ($destination->translation_sets as $translation_set) {
    $destination_locales[$translation_set->locale] = sprintf('%s/%s', $translation_set->locale, $translation_set->slug);
}
if (isset($argv[2])) {
    $origin_urls = array_map('apize_url', array_slice($argv, 2));
} else {
    /*
    	// Imports all siblings into destination
    	$origin_urls = array();
    	$destination_parent_url = rtrim( dirname( $destination_url ), '/' );
    	$destination_parent = json_decode( file_get_contents( $destination_parent_url ) );
    	foreach ( $destination_parent->sub_projects as $sub_project ) {
    		$origin_url = sprintf( '%s/%s', $destination_parent_url, $sub_project->slug );
Example #2
0
$temp_file_meta = stream_get_meta_data($temp_file_handle);
// file meta data
$temp_file_path = $temp_file_meta['uri'];
// file path
fclose($temp_file_handle);
mkdir($temp_file_path, 0700, true);
register_shutdown_function(function ($temp_file_path) {
    exec(sprintf('rm -rf %s', escapeshellarg($temp_file_path)));
}, $temp_file_path);
// The current Jetpack translations
$current_sets = glob($jetpack_directory . '/languages/*.mo');
$current_sets = preg_replace('/.*-(\\w+)\\.mo/', '$1', $current_sets);
$keys = array_map('strtolower', $current_sets);
$current_sets = array_combine($keys, $current_sets);
unset($keys);
$source_url = apize_url(rtrim($argv[2], '/'));
$source = file_get_contents($source_url);
$available_sets = json_decode($source)->translation_sets;
// Maps source locale slugs to current Jetpack locales
$map = $language_pack = array();
foreach ($available_sets as $set) {
    $s = strtolower(str_replace('-', '_', $set->locale));
    if (GP_Locales::exists($set->locale)) {
        $locale = GP_Locales::by_slug($set->locale);
        if (in_array($set->locale, $language_packs)) {
            $language_pack[$set->locale] = $locale->wp_locale;
            continue;
        }
        $map[$set->locale] = $locale->wp_locale;
        continue;
    }