@@ -17,41 +17,76 @@ class Translation
1717 protected $ flags = array ();
1818 protected $ translationCount ;
1919
20+ /**
21+ * Generates the id of a translation (context + glue + original)
22+ *
23+ * @param string $context
24+ * @param string $original
25+ *
26+ * @return string
27+ */
28+ public static function generateId ($ context , $ original )
29+ {
30+ return "{$ context }\004{$ original }" ;
31+ }
32+
2033 /**
2134 * Construct
2235 *
2336 * @param string $context The context of the translation
2437 * @param string $original The original string
2538 * @param string $plural The original plural string
2639 */
27- public function __construct ($ context = '' , $ original = '' , $ plural = '' )
40+ public function __construct ($ context , $ original , $ plural = '' )
2841 {
29- $ this ->setContext ($ context );
30- $ this ->setOriginal ($ original );
42+ $ this ->context = (string ) $ context ;
43+ $ this ->original = (string ) $ original ;
44+
3145 $ this ->setPlural ($ plural );
3246 }
3347
3448 /**
35- * Checks whether the translation matches with the arguments
49+ * Clones this translation
3650 *
37- * @param string $context
38- * @param string $original
51+ * @param null|string $context Optional new context
52+ * @param null|string $original Optional new original
53+ */
54+ public function getClone ($ context = null , $ original = null )
55+ {
56+ $ new = clone $ this ;
57+
58+ if ($ context !== null ) {
59+ $ new ->context = (string ) $ context ;
60+ }
61+
62+ if ($ original !== null ) {
63+ $ new ->original = (string ) $ original ;
64+ }
65+
66+ return $ new ;
67+ }
68+
69+ /**
70+ * Returns the id of this translation
3971 *
40- * @return boolean
72+ * @return string
4173 */
42- public function is ( $ context , $ original = '' )
74+ public function getId ( )
4375 {
44- return (( $ this ->context === $ context ) && ( $ this ->original === $ original )) ? true : false ;
76+ return static :: generateId ( $ this ->context , $ this ->original ) ;
4577 }
4678
4779 /**
48- * Sets the original string
80+ * Checks whether the translation matches with the arguments
4981 *
82+ * @param string $context
5083 * @param string $original
84+ *
85+ * @return boolean
5186 */
52- public function setOriginal ( $ original )
87+ public function is ( $ context , $ original = '' )
5388 {
54- $ this ->original = ( string ) $ original ;
89+ return (( $ this ->context === $ context ) && ( $ this -> original === $ original )) ? true : false ;
5590 }
5691
5792 /**
@@ -230,16 +265,6 @@ protected function normalizeTranslationCount()
230265 }
231266 }
232267
233- /**
234- * Sets the context of this translation
235- *
236- * @param string $context
237- */
238- public function setContext ($ context )
239- {
240- $ this ->context = (string ) $ context ;
241- }
242-
243268 /**
244269 * Gets the context of this translation
245270 *
0 commit comments