PluginProbe
Polylang / 3.4.5
Polylang v3.4.5
3.8.9 3.8.8 3.8.7 3.8.6 3.8.5 3.8.4 3.8.3 2.7 2.7.0.1 2.7.1 2.7.2 2.7.3 2.7.4 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.9 2.9.1 2.9.2 3.0 3.0.1 3.0.2 3.0.3 All 233 releases
polylang / include / mo.php

mo.php in Polylang 3.4.5, at include/mo.php

78 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package Polylang
4 */
5
6 /**
7 * Manages strings translations storage
8 *
9 * @since 1.2
10 * @since 2.1 Stores the strings in a post meta instead of post content to avoid unserialize issues (See #63)
11 * @since 3.4 Stores the strings into language taxonomy term meta instead of a post meta.
12 */
13 class PLL_MO extends MO {
14
15 /**
16 * Writes the strings into a term meta.
17 *
18 * @since 1.2
19 *
20 * @param PLL_Language $lang The language in which we want to export strings.
21 * @return void
22 */
23 public function export_to_db( $lang ) {
24 /*
25 * It would be convenient to store the whole object, but it would take a huge space in DB.
26 * So let's keep only the strings in an array.
27 * The strings are slashed to avoid breaking slashed strings in update_term_meta.
28 * @see https://codex.wordpress.org/Function_Reference/update_post_meta#Character_Escaping.
29 */
30 $strings = array();
31 foreach ( $this->entries as $entry ) {
32 if ( '' !== $entry->singular ) {
33 $strings[] = wp_slash( array( $entry->singular, $this->translate( $entry->singular ) ) );
34 }
35 }
36
37 update_term_meta( $lang->term_id, '_pll_strings_translations', $strings );
38 }
39
40 /**
41 * Reads a PLL_MO object from the term meta.
42 *
43 * @since 1.2
44 * @since 3.4 Reads a PLL_MO from the term meta.
45 *
46 * @param PLL_Language $lang The language in which we want to get strings.
47 * @return void
48 */
49 public function import_from_db( $lang ) {
50 $this->set_header( 'Language', $lang->slug );
51
52 $strings = get_term_meta( $lang->term_id, '_pll_strings_translations', true );
53 if ( empty( $strings ) || ! is_array( $strings ) ) {
54 return;
55 }
56
57 foreach ( $strings as $msg ) {
58 $entry = $this->make_entry( $msg[0], $msg[1] );
59
60 if ( '' !== $entry->singular ) {
61 $this->add_entry( $entry );
62 }
63 }
64 }
65
66 /**
67 * Deletes a string
68 *
69 * @since 2.9
70 *
71 * @param string $string The source string to remove from the translations.
72 * @return void
73 */
74 public function delete_entry( $string ) {
75 unset( $this->entries[ $string ] );
76 }
77 }
78