PluginProbe
Bogo / 2.9
Bogo v2.9
3.9.3 trunk 1.0 1.1 2.0 2.0.1 2.1 2.1.1 2.1.2 2.1.3 2.2 2.3 2.4 2.4.1 2.4.2 2.4.3 2.5 2.6 2.6.1 2.7 2.8 2.8.1 2.9 3.0 3.0.1 All 52 releases
bogo / includes / pomo.php

pomo.php in Bogo 2.9, at includes/pomo.php

106 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 add_filter( 'bloginfo', 'bogo_bloginfo_filter', 10, 2 );
4
5 function bogo_bloginfo_filter( $output, $show ) {
6 if ( 'name' == $show ) {
7 $output = bogo_translate( 'blogname', 'blogname', $output );
8 } elseif ( 'description' == $show ) {
9 $output = bogo_translate( 'blogdescription', 'blogdescription', $output );
10 }
11
12 return $output;
13 }
14
15 function bogo_translate( $singular, $context = '', $default = '' ) {
16 return Bogo_POMO::translate( $singular, $context, $default );
17 }
18
19 class Bogo_POMO {
20
21 private static $mo;
22
23 public static function translate( $singular, $context = '', $default = '' ) {
24 if ( ! self::$mo ) {
25 return '' !== $default ? $default : $singular;
26 }
27
28 $translated = self::$mo->translate( $singular, $context );
29
30 if ( $translated == $singular && '' !== $default ) {
31 return $default;
32 } else {
33 return $translated;
34 }
35 }
36
37 public static function export( $locale, $entries = array() ) {
38 if ( ! bogo_is_available_locale( $locale ) ) {
39 return false;
40 }
41
42 $dir = self::dir();
43
44 $headers = array(
45 'PO-Revision-Date' => current_time( 'mysql', 'gmt' ) . '+0000',
46 'MIME-Version' => '1.0',
47 'Content-Type' => 'text/plain; charset=UTF-8',
48 'Content-Transfer-Encoding' => '8bit',
49 'X-Generator' => sprintf( 'Bogo %s', BOGO_VERSION ),
50 'Language' => $locale,
51 'Project-Id-Version' =>
52 sprintf( 'WordPress %s', get_bloginfo( 'version' ) ) );
53
54 require_once ABSPATH . WPINC . '/pomo/po.php';
55 $po = new PO();
56 $po->set_headers( $headers );
57
58 foreach ( (array) $entries as $entry ) {
59 $entry = new Translation_Entry( $entry );
60 $po->add_entry( $entry );
61 }
62
63 $po->export_to_file( path_join( $dir, $locale . '.po' ) );
64
65 $mo = new MO();
66 $mo->set_headers( $headers );
67
68 foreach ( (array) $entries as $entry ) {
69 $entry = new Translation_Entry( $entry );
70 $mo->add_entry( $entry );
71 }
72
73 return $mo->export_to_file( path_join( $dir, $locale . '.mo' ) );
74 }
75
76 public static function import( $locale ) {
77 if ( ! bogo_is_available_locale( $locale ) ) {
78 return false;
79 }
80
81 $dir = self::dir();
82
83 $mo_file = path_join( $dir, $locale . '.mo' );
84
85 if ( ! is_readable( $mo_file ) ) {
86 return false;
87 }
88
89 $mo = new MO();
90
91 if ( ! $mo->import_from_file( $mo_file ) ) {
92 return false;
93 }
94
95 self::$mo = $mo;
96 return true;
97 }
98
99 private static function dir() {
100 $dir = path_join( WP_LANG_DIR, 'bogo' );
101 $dir = apply_filters( 'bogo_pomo_dir', $dir );
102 wp_mkdir_p( $dir );
103 return $dir;
104 }
105 }
106