PluginProbe ʕ •ᴥ•ʔ
Loco Translate / 1.1.3
Loco Translate v1.1.3
2.8.5 2.8.4 2.5.8 2.6.0 2.6.1 2.6.10 2.6.11 2.6.12 2.6.13 2.6.14 2.6.2 2.6.3 2.6.4 2.6.5 2.6.6 2.6.7 2.6.8 2.6.9 2.7.0 2.7.1 2.7.2 2.7.3 2.8.0 2.8.1 2.8.2 2.8.3 trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.2 1.2.1 1.2.2 1.3 1.3.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.5 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 2.0.0 2.0.1 2.0.10 2.0.11 2.0.12 2.0.13 2.0.14 2.0.15 2.0.16 2.0.17 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2.0 2.2.1 2.2.2 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7
loco-translate / php / loco-posync.php
loco-translate / php Last commit date
loco-ajax.php 12 years ago loco-download.php 12 years ago loco-fail.php 12 years ago loco-fatal.php 12 years ago loco-posave.php 12 years ago loco-posync.php 12 years ago
loco-posync.php
62 lines
1 <?php
2 /**
3 * Admin ajax include that syncs PO or POT file with sources
4 */
5
6 DOING_AJAX or die();
7
8 if( empty($path) || empty($root) ){
9 throw new Exception( Loco::__('Invalid data posted to server'), 422 );
10 }
11
12 // path is allowed not exist
13 if( '/' !== $path{0} ){
14 $path = WP_CONTENT_DIR.'/'.$path;
15 }
16
17 // but root must
18 $root = LocoAdmin::resolve_path( $root, true );
19
20 while( true ){
21
22 // If file we're syncing is POT, we can only sync from sources
23 if( ! LocoAdmin::is_pot($path) ){
24
25 // if a POT file exists, sync from that.
26 foreach( LocoAdmin::find_pot($root) as $pot_path ){
27 $exp = LocoAdmin::parse_po( $pot_path );
28 if( ! $exp || ( 1 === count($exp) && '' === $exp[0]['source'] ) ){
29 //throw new Exception( Loco::__('POT file is empty') );
30 continue;
31 }
32 $pot = basename($pot_path);
33 break 2;
34 }
35
36 }
37
38 // Extract from sources by default
39 if( $exp = LocoAdmin::xgettext($root) ){
40 $pot = '';
41 break;
42 }
43
44 throw new Exception( Loco::__('No strings could be extracted from source files') );
45 }
46
47
48 // sync selected headers
49 $headers = array();
50 if( '' === $exp[0]['source'] ){
51 $keep = array('Project-Id-Version'=>'','Language-Team'=>'','POT-Creation-Date'=>'','POT-Revision-Date'=>'');
52 $head = loco_parse_po_headers( $exp[0]['target'] );
53 $headers = array_intersect_key( $head->to_array(), $keep );
54 $exp[0] = array();
55 }
56
57
58 // sync ok.
59 return compact( 'pot', 'exp', 'headers' );
60
61
62