Skip to content

Instantly share code, notes, and snippets.

@csalzano
Last active September 22, 2024 13:20
Show Gist options
  • Save csalzano/8cf894b1a9754b384c39d1c479ab1372 to your computer and use it in GitHub Desktop.
Save csalzano/8cf894b1a9754b384c39d1c479ab1372 to your computer and use it in GitHub Desktop.
<?php
/**
* I hired a translator to translate my plugin into Spanish (Mexico). I want to
* create variants for the 13 other Spanish locales on translate.wordpress.org.
*/
$es_mx_file_paths = array(
'wp-plugins-inventory-presser-stable-es-mx.po',
'wp-plugins-inventory-presser-stable-readme-es-mx.po',
);
$slugs = array(
'es_AR' => 'Spanish (Argentina)',
'es_CL' => 'Spanish (Chile)',
'es_CO' => 'Spanish (Colombia)',
'es_CR' => 'Spanish (Costa Rica)',
'es_DO' => 'Spanish (Dominican Republic)',
'es_EC' => 'Spanish (Ecuador)',
'es_GT' => 'Spanish (Guatemala)',
'es_HN' => 'Spanish (Honduras)',
//'es_MX' => 'Spanish (Mexico)',
'es_PE' => 'Spanish (Peru)',
'es_PR' => 'Spanish (Puerto Rico)',
'es' => 'Spanish (Spain)',
'es_UY' => 'Spanish (Uruguay)',
'es_VE' => 'Spanish (Venezuela)',
);
foreach ( $es_mx_file_paths as $es_mx_file_path ) {
$file_contents = file_get_contents( $es_mx_file_path );
foreach ( $slugs as $slug => $name ) {
// Copy the file contents.
$new_file_contents = $file_contents;
// Replace slug.
$new_file_contents = str_replace( 'es_MX', $slug, $new_file_contents );
// Replace name.
$new_file_contents = str_replace( 'Spanish (Mexico)', $name, $new_file_contents );
// Generate file name.
$new_file_name = str_replace( 'es-mx', str_replace( '_', '-', strtolower( $slug ) ), $es_mx_file_path );
// Write the file.
file_put_contents( $new_file_name, $new_file_contents );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment