Skip to content

Instantly share code, notes, and snippets.

@dimadin
Created July 29, 2015 13:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dimadin/38faa70eb38cb9dc1f94 to your computer and use it in GitHub Desktop.
Save dimadin/38faa70eb38cb9dc1f94 to your computer and use it in GitHub Desktop.
GlotPress Serbian transliteration
<?php
function __construct() {
$this->short_options .= 'o:v:';
$this->usage .= ' [-o <format (default=po)>] [-v <variant>]';
$this->add_filters_to_options_and_usage();
parent::__construct();
}
function action_on_translation_set( $translation_set ) {
$format = gp_array_get( GP::$formats, isset( $this->options['o'] )? $this->options['o'] : 'po', null );
if ( !$format ) $this->error( __('No such format.') );;
if ( isset( $this->options['v'] ) ) {
$_GET['variant'] = $this->options['v'];
}
$entries = GP::$translation->for_export( $this->project, $translation_set, $this->get_filters_for_translation() );
echo $format->print_exported_file( $this->project, $this->locale, $translation_set, $entries )."\n";
}
<?php
function find_all_translations_for_type_and_domain( $type, $domain = 'default', $version = null ) {
$sr_latin = clone GP_Locales::by_field( 'wp_locale', 'sr_RS' );
$sr_latin->english_name = 'Serbian (Latin)';
$sr_latin->native_name = 'Српски (латиница)';
$sr_latin->slug = 'sr';
$sr_latin->wp_locale = 'sr_RS@Latin'; // Both slug and this should probably change
$GLOBALS['gp_locales']->locales['sr/latin'] = $sr_latin;
}
<?php
class GP_Serbian_Latin extends GP_Plugin {
public $id = 'serbian-latin';
var $replace_pairs = array(
'А' => 'A',
'Б' => 'B',
'В' => 'V',
'Г' => 'G',
'Д' => 'D',
'Ђ' => 'Đ',
'Е' => 'E',
'Ж' => 'Ž',
'З' => 'Z',
'И' => 'I',
'Ј' => 'J',
'К' => 'K',
'Л' => 'L',
'Љ' => 'Lj',
'М' => 'M',
'Н' => 'N',
'Њ' => 'Nj',
'О' => 'O',
'П' => 'P',
'Р' => 'R',
'С' => 'S',
'Т' => 'T',
'Ћ' => 'Ć',
'У' => 'U',
'Ф' => 'F',
'Х' => 'H',
'Ц' => 'C',
'Ч' => 'Č',
'Џ' => 'Dž',
'Ш' => 'Š',
'а' => 'a',
'б' => 'b',
'в' => 'v',
'г' => 'g',
'д' => 'd',
'ђ' => 'đ',
'е' => 'e',
'ж' => 'ž',
'з' => 'z',
'и' => 'i',
'ј' => 'j',
'к' => 'k',
'л' => 'l',
'љ' => 'lj',
'м' => 'm',
'н' => 'n',
'њ' => 'nj',
'о' => 'o',
'п' => 'p',
'р' => 'r',
'с' => 's',
'т' => 't',
'ћ' => 'ć',
'у' => 'u',
'ф' => 'f',
'х' => 'h',
'ц' => 'c',
'ч' => 'č',
'џ' => 'dž',
'ш' => 'š',
);
public function __construct() {
parent::__construct();
$this->add_filter( 'export_translations_filename', array( 'args' => 5 ) );
$this->add_filter( 'for_export_translations', array( 'args' => 2 ) );
}
public function export_translations_filename( $filename, $format, $locale, $project, $translation_set ) {
if ( 'sr' == $translation_set->locale && 'latin' == gp_get( 'variant' ) ) {
$filename = str_replace( 'sr', 'sr-latin', $filename );
}
return $filename;
}
public function for_export_translations( $translation_entries, $translation_set ) {
if ( 'sr' == $translation_set->locale && 'latin' == gp_get( 'variant' ) ) {
foreach ( $translation_entries as $translation_entry ) {
foreach ( $translation_entry->translations as &$translation ) {
$translation = strtr( $translation, $this->replace_pairs );
}
}
}
return $translation_entries;
}
}
GP::$plugins->serbian_latin = new GP_Serbian_Latin;
<?php
function for_export( $project, $translation_set, $filters = null ) {
$translations = GP::$translation->for_translation( $project, $translation_set, 'no-limit', $filters? $filters : array( 'status' => 'current_or_untranslated' ) );
$translations = apply_filters( 'for_export_translations', $translations, $translation_set, $filters );
return $translations;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment