Zend_Translate-Additional.xml 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.translate.additional">
  4. <title>Additional features for translation</title>
  5. <para>
  6. There are several additional features which are supported by
  7. <classname>Zend_Translate</classname>. Read here for these additional informations.
  8. </para>
  9. <sect2 id="zend.translate.additional.options">
  10. <title>Options for adapters</title>
  11. <para>
  12. Options can be used with all adapters. Of course the options are different for all adapters.
  13. You can set options when you create the adapter. Actually there is one option which is available
  14. to all adapters: '<code>clear</code>' sets if translation data should be added to existing
  15. one or not. Standard behaviour is to add new translation data to existing one. But the
  16. translation data is only cleared for the selected language. So other languages remain
  17. untouched.
  18. </para>
  19. <para>
  20. You can set options temporarily when using <code>addTranslation($data, $locale, array $options = array())</code>
  21. as third and optional parameter. And you can use the method <code>setOptions()</code> to
  22. set the options permanently.
  23. </para>
  24. <example id="zend.translate..additional.options.example">
  25. <title>Using translation options</title>
  26. <programlisting role="php"><![CDATA[
  27. // define ':' as separator for the translation source files
  28. $options = array('delimiter' => ':');
  29. $translate = new Zend_Translate(
  30. 'csv',
  31. '/path/to/mytranslation.csv',
  32. 'de',
  33. $options);
  34. ...
  35. // clear the defined language and use new translation data
  36. $options = array('clear' => true);
  37. $translate->addTranslation('/path/to/new.csv', 'fr', $options);
  38. ]]></programlisting>
  39. </example>
  40. <para>
  41. Here you can find all available options for the different adapters with a description of their usage:
  42. </para>
  43. <table id="zend.translate.additional.options.alloptions">
  44. <title>Options for translation adapters</title>
  45. <tgroup cols="4">
  46. <thead>
  47. <row>
  48. <entry>Option</entry>
  49. <entry>Adapter</entry>
  50. <entry>Description</entry>
  51. <entry>Default value</entry>
  52. </row>
  53. </thead>
  54. <tbody>
  55. <row>
  56. <entry>clear</entry>
  57. <entry>all</entry>
  58. <entry>
  59. If set to true, the already read translations will be cleared. This can be used
  60. instead of creating a new instance when reading new translation data
  61. </entry>
  62. <entry><emphasis>false</emphasis></entry>
  63. </row>
  64. <row>
  65. <entry>disableNotices</entry>
  66. <entry>all</entry>
  67. <entry>
  68. If set to true, all notices regarding not available translations will be
  69. disabled. You should set this option to true in production environment
  70. </entry>
  71. <entry><emphasis>false</emphasis></entry>
  72. </row>
  73. <row>
  74. <entry>ignore</entry>
  75. <entry>all</entry>
  76. <entry>
  77. All directories and files beginning with this prefix will be ignored when
  78. searching for files. This value defaults to <emphasis>'.'</emphasis>
  79. which leads to the behavior that all hidden files will be ignored. Setting this
  80. value to <code>'tmp'</code> would mean that directories and files like
  81. <code>'tmpImages'</code> and <code>'tmpFiles'</code>
  82. would be ignored as well as all subsequent directories
  83. </entry>
  84. <entry><emphasis>.</emphasis></entry>
  85. </row>
  86. <row>
  87. <entry>log</entry>
  88. <entry>all</entry>
  89. <entry>
  90. An instance of <classname>Zend_Log</classname> where untranslated messages and notices will be
  91. written to
  92. </entry>
  93. <entry><emphasis>null</emphasis></entry>
  94. </row>
  95. <row>
  96. <entry>logMessage</entry>
  97. <entry>all</entry>
  98. <entry>
  99. The message which will be written into the log
  100. </entry>
  101. <entry><emphasis>Untranslated message within '%locale%': %message%</emphasis></entry>
  102. </row>
  103. <row>
  104. <entry>logUntranslated</entry>
  105. <entry>all</entry>
  106. <entry>
  107. When this option is set to true, all message IDs which can not be
  108. translated will be written into the attached log
  109. </entry>
  110. <entry><emphasis>false</emphasis></entry>
  111. </row>
  112. <row>
  113. <entry>scan</entry>
  114. <entry>all</entry>
  115. <entry>
  116. If set to null, no scanning of the directory structure will be done.
  117. If set to <classname>Zend_Translate::LOCALE_DIRECTORY</classname> the locale will be detected within the
  118. directory. If set to <classname>Zend_Translate::LOCALE_FILENAME</classname> the locale will be detected
  119. within the filename. See <xref linkend="zend.translate.additional.detection" />
  120. for details
  121. </entry>
  122. <entry><emphasis>null</emphasis></entry>
  123. </row>
  124. <row>
  125. <entry>delimiter</entry>
  126. <entry>Csv</entry>
  127. <entry>Defines which sign is used as delimiter for separating source and translation</entry>
  128. <entry><emphasis>;</emphasis></entry>
  129. </row>
  130. <row>
  131. <entry>enclosure</entry>
  132. <entry>Csv</entry>
  133. <entry>Defines the enclosure character to be used. Defaults to a doublequote</entry>
  134. <entry><emphasis>"</emphasis></entry>
  135. </row>
  136. <row>
  137. <entry>length</entry>
  138. <entry>Csv</entry>
  139. <entry>Defines the maximum length of a csv line. When set to 0 it will be detected automatically</entry>
  140. <entry><emphasis>0</emphasis></entry>
  141. </row>
  142. </tbody>
  143. </tgroup>
  144. </table>
  145. <para>
  146. When you want to have self defined options, you are also able to use them within all adapters.
  147. The <code>setOptions()</code> method can be used to define your option. <code>setOptions()</code>
  148. needs an array with the options you want to set. If an given option exists it will be signed over.
  149. You can define as much options as needed as they will not be checked by the adapter. Just make sure
  150. not to overwrite any existing option which is used by an adapter.
  151. </para>
  152. <para>
  153. To return the option you can use the <code>getOptions()</code> method. When <code>getOptions()</code>
  154. is called without a parameter it will return all options set. When the optional parameter is given
  155. you will only get the specified option.
  156. </para>
  157. </sect2>
  158. <sect2 id="zend.translate.additional.languages">
  159. <title>Handling languages</title>
  160. <para>
  161. When working with different languages there are a few methods which will be useful.
  162. </para>
  163. <para>
  164. The <code>getLocale()</code> method can be used to get the currently set language. It can either hold
  165. an instance of <classname>Zend_Locale</classname> or the identifier of a locale.
  166. </para>
  167. <para>
  168. The <code>setLocale()</code> method sets a new standard language for translation. This prevents the
  169. need of setting the optional language parameter more than once to the <code>translate()</code> method.
  170. If the given language does not exist, or no translation data is available for the language,
  171. <code>setLocale()</code> tries to downgrade to the language without the region if any was given.
  172. A language of <code>en_US</code> would be downgraded to <code>en</code>. When even the downgraded
  173. language can not be found an exception will be thrown.
  174. </para>
  175. <para>
  176. The <code>isAvailable()</code> method checks if a given language is already available. It returns
  177. <constant>TRUE</constant> if data for the given language exist.
  178. </para>
  179. <para>
  180. And finally the <code>getList()</code> method can be used to get all currently set languages for an adapter
  181. returned as array.
  182. </para>
  183. <example id="zend.translate.additional.languages.example">
  184. <title>Handling languages with adapters</title>
  185. <programlisting role="php"><![CDATA[
  186. // returns the currently set language
  187. $actual = $translate->getLocale();
  188. // you can use the optional parameter while translating
  189. echo $translate->_("my_text", "fr");
  190. // or set a new language
  191. $translate->setLocale("fr");
  192. echo $translate->_("my_text");
  193. // refer to the base language
  194. // fr_CH will be downgraded to fr
  195. $translate->setLocale("fr_CH");
  196. echo $translate->_("my_text");
  197. // check if this language exist
  198. if ($translate->isAvailable("fr")) {
  199. // language exists
  200. }
  201. ]]></programlisting>
  202. </example>
  203. <sect3 id="zend.translate.additional.languages.automatic">
  204. <title>Automatical handling of languages</title>
  205. <para>
  206. Note that as long as you only add new translation sources with the <code>addTranslation()</code>
  207. method <classname>Zend_Translate</classname> will automatically set the best fitting language for your
  208. environment when you use one of the automatic locales which are '<code>auto</code>' or '<code>browser</code>'. So
  209. normally you will not need to call <code>setLocale()</code>. This should only be used in
  210. conjunction with automatic source detection.
  211. </para>
  212. <para>
  213. The algorithm will search for the best fitting locale depending on the user's browser and
  214. your environment. See the following example for details:
  215. </para>
  216. <example id="zend.translate.additional.languages.automatic.example">
  217. <title>Automatically language detection</title>
  218. <programlisting role="php"><![CDATA[
  219. // Let's expect the browser returns these language settings:
  220. // HTTP_ACCEPT_LANGUAGE = "de_AT=1;fr=1;en_US=0.8";
  221. // Example 1:
  222. // When no fitting language is found, the message ID is returned
  223. $translate = new Zend_Translate(
  224. 'gettext',
  225. 'my_it.mo',
  226. 'auto',
  227. array('scan' => Zend_Translate::LOCALE_FILENAME));
  228. // Example 2:
  229. // Best found fitting language is 'fr'
  230. $translate = new Zend_Translate(
  231. 'gettext',
  232. 'my_fr.mo',
  233. 'auto',
  234. array('scan' => Zend_Translate::LOCALE_FILENAME));
  235. // Example 3:
  236. // Best found fitting language is 'de' ('de_AT' will be degraded)
  237. $translate = new Zend_Translate(
  238. 'gettext',
  239. 'my_de.mo',
  240. 'auto',
  241. array('scan' => Zend_Translate::LOCALE_FILENAME));
  242. // Example 4:
  243. // Returns 'it' as translation source and overrides the automatic settings
  244. $translate = new Zend_Translate(
  245. 'gettext',
  246. 'my_it.mo',
  247. 'auto',
  248. array('scan' => Zend_Translate::LOCALE_FILENAME));
  249. $translate->addTranslation('my_ru.mo', 'ru');
  250. $translate->setLocale('it_IT');
  251. ]]></programlisting>
  252. </example>
  253. <para>
  254. After setting a language manually with the <code>setLocale()</code> method the automatic
  255. detection will be switched off and overridden.
  256. </para>
  257. <para>
  258. If you want to use it again, you can set the language
  259. <emphasis>auto</emphasis> with <code>setLocale()</code> which will reactivate
  260. the automatic detection for <classname>Zend_Translate</classname>.
  261. </para>
  262. <para>
  263. Since Zend Framework 1.7.0 <classname>Zend_Translate</classname> also recognises an application
  264. wide locale. You can simply set a <classname>Zend_Locale</classname> instance to the registry like shown
  265. below. With this notation you can forget about setting the locale manually with each instance
  266. when you want to use the same locale multiple times.
  267. </para>
  268. <programlisting role="php"><![CDATA[
  269. // in your bootstrap file
  270. $locale = new Zend_Locale();
  271. Zend_Registry::set('Zend_Locale', $locale);
  272. // default language when requested language is not available
  273. $defaultlanguage = 'en';
  274. // somewhere in your application
  275. $translate = new Zend_Translate('gettext', 'my_de.mo');
  276. if (!$translate->isAvailable($locale->getLanguage())) {
  277. // not available languages are rerouted to another language
  278. $translate->setLocale($defaultlanguage);
  279. }
  280. $translate->getLocale();
  281. ]]></programlisting>
  282. </sect3>
  283. </sect2>
  284. <sect2 id="zend.translate.additional.detection">
  285. <title>Automatic source detection</title>
  286. <para>
  287. <classname>Zend_Translate</classname> can detect translation sources automatically. So you don't have
  288. to declare each source file manually. You can let <classname>Zend_Translate</classname> do this job and
  289. scan the complete directory structure for source files.
  290. </para>
  291. <note>
  292. <para>
  293. Automatic source detection is available since Zend Framework version 1.5 .
  294. </para>
  295. </note>
  296. <para>
  297. The usage is quite the same as initiating a single translation source with one difference.
  298. You must give a directory which has to be scanned instead a file.
  299. </para>
  300. <example id="zend.translate.additional.languages.directory.example">
  301. <title>Scanning a directory structure for sources</title>
  302. <programlisting role="php"><![CDATA[
  303. // assuming we have the following structure
  304. // /language/
  305. // /language/login/login.tmx
  306. // /language/logout/logout.tmx
  307. // /language/error/loginerror.tmx
  308. // /language/error/logouterror.tmx
  309. $translate = new Zend_Translate('tmx', '/language');
  310. ]]></programlisting>
  311. </example>
  312. <para>
  313. So <classname>Zend_Translate</classname> does not only search the given directory, but also all subdirectories for
  314. translation source files. This makes the usage quite simple. But <classname>Zend_Translate</classname> will ignore all
  315. files which are not sources or which produce failures while reading the translation data. So you
  316. have to make sure that all of your translation sources are correct and readable because you will
  317. not get any failure if a file is bogus or can not be read.
  318. </para>
  319. <note>
  320. <para>
  321. Depending on how deep your directory structure is and how much files are within this structure
  322. it can take a long time for <classname>Zend_Translate</classname> to complete.
  323. </para>
  324. </note>
  325. <para>
  326. In our example we have used the TMX format which includes the language to be used within the
  327. source. But many of the other source formats are not able to include the language within the
  328. file. Even this sources can be used with automatic scanning if you do some pre-requisits as
  329. described below:
  330. </para>
  331. <sect3 id="zend.translate.additional.detection.directory">
  332. <title>Language through naming directories</title>
  333. <para>
  334. One way to include automatic language detection is to name the directories related to the
  335. language which is used for the sources within this directory. This is the easiest way and
  336. is used for example within standard gettext implementations.
  337. </para>
  338. <para>
  339. <classname>Zend_Translate</classname> needs the '<code>scan</code>' option to know that it should search the names of all
  340. directories for languages. See the following example for details:
  341. </para>
  342. <example id="zend.translate.additional.detection.directory.example">
  343. <title>Directory scanning for languages</title>
  344. <programlisting role="php"><![CDATA[
  345. // assuming we have the following structure
  346. // /language/
  347. // /language/de/login/login.mo
  348. // /language/de/error/loginerror.mo
  349. // /language/en/login/login.mo
  350. // /language/en/error/loginerror.mo
  351. $translate = new Zend_Translate(
  352. 'gettext',
  353. '/language',
  354. null,
  355. array('scan' => Zend_Translate::LOCALE_DIRECTORY));
  356. ]]></programlisting>
  357. </example>
  358. <note>
  359. <para>
  360. This works only for adapters which do not include the language within the source file.
  361. Using this option for example with TMX will be ignored. Also language definitions within
  362. the filename will be ignored when using this option.
  363. </para>
  364. </note>
  365. <note>
  366. <para>
  367. You should be aware if you have several subdirectories under the same
  368. structure. Assuming we have a structure like
  369. <code>/language/module/de/en/file.mo</code>. In this case the path contains
  370. multiple strings which would be detected as locale. It could be either
  371. <code>de</code> or <code>en</code>. In such a case the behaviour is
  372. undefined and it is recommended to use file detection in such situations.
  373. </para>
  374. </note>
  375. </sect3>
  376. <sect3 id="zend.translate.additional.detection.filename">
  377. <title>Language through filenames</title>
  378. <para>
  379. Another way to detect the language automatically is to use special filenames. You can either
  380. name the complete file or parts of a file after the used language. To use this way of detection
  381. you will have to set the '<code>scan</code>' option at initiation. There are several ways of naming the
  382. sourcefiles which are described below:
  383. </para>
  384. <example id="zend.translate.additional.detection.filename.example">
  385. <title>Filename scanning for languages</title>
  386. <programlisting role="php"><![CDATA[
  387. // assuming we have the following structure
  388. // /language/
  389. // /language/login/login_en.mo
  390. // /language/login/login_de.mo
  391. // /language/error/loginerror_en.mo
  392. // /language/error/loginerror_de.mo
  393. $translate = new Zend_Translate(
  394. 'gettext',
  395. '/language',
  396. null,
  397. array('scan' => Zend_Translate::LOCALE_FILENAME));
  398. ]]></programlisting>
  399. </example>
  400. <sect4 id="zend.translate.additional.detection.filename.complete">
  401. <title>Complete filename</title>
  402. <para>
  403. Having the whole file named after the language is the simplest way but only viable
  404. if you have only one file per language.
  405. </para>
  406. <programlisting language="txt"><![CDATA[
  407. /languages/
  408. /languages/en.mo
  409. /languages/de.mo
  410. /languages/es.mo
  411. ]]></programlisting>
  412. </sect4>
  413. <sect4 id="zend.translate.additional.detection.filename.extension">
  414. <title>Extension of the file</title>
  415. <para>
  416. Another simple way to use the extension of the file for language detection.
  417. But this may be confusing since you will no longer have an idea which extension the file
  418. originally had.
  419. </para>
  420. <programlisting language="txt"><![CDATA[
  421. /languages/
  422. /languages/view.en
  423. /languages/view.de
  424. /languages/view.es
  425. ]]></programlisting>
  426. </sect4>
  427. <sect4 id="zend.translate.additional.detection.filename.token">
  428. <title>Filename tokens</title>
  429. <para>
  430. <classname>Zend_Translate</classname> is also capable of detecting the language if it is included within the
  431. filename. But if you go this way you will have to separate the language with a token.
  432. There are three supported tokens which can be used: a dot '.', an underscore '_', or
  433. a hyphen '-'.
  434. </para>
  435. <programlisting language="txt"><![CDATA[
  436. /languages/
  437. /languages/view_en.mo -> detects english
  438. /languages/view_de.mo -> detects german
  439. /languages/view_it.mo -> detects italian
  440. ]]></programlisting>
  441. <para>
  442. The first found string delimited by a token which can be interpreted as a locale will be used. See the following
  443. example for details.
  444. </para>
  445. <programlisting language="txt"><![CDATA[
  446. /languages/
  447. /languages/view_en_de.mo -> detects english
  448. /languages/view_en_es.mo -> detects english and overwrites the first file
  449. /languages/view_it_it.mo -> detects italian
  450. ]]></programlisting>
  451. <para>
  452. All three tokens are used to detect the locale. When the filename contains multiple tokens,
  453. the first found token depends on the order of the tokens which are used. See the following
  454. example for details.
  455. </para>
  456. <programlisting language="txt"><![CDATA[
  457. /languages/
  458. /languages/view_en-it.mo -> detects english because '_' will be used before '-'
  459. /languages/view-en_it.mo -> detects italian because '_' will be used before '-'
  460. /languages/view_en.it.mo -> detects italian because '.' will be used before '_'
  461. ]]></programlisting>
  462. </sect4>
  463. </sect3>
  464. </sect2>
  465. <sect2 id="zend.translate.additional.istranslated">
  466. <title>Checking for translations</title>
  467. <para>
  468. Normally text will be translated without any computation. But sometimes it is necessary to
  469. know if a text is translated or not, therefor the <code>isTranslated()</code>
  470. method can be used.
  471. </para>
  472. <para>
  473. <code>isTranslated($messageId, $original = false, $locale = null)</code> takes
  474. the text you want to check as its first parameter, and as optional third parameter the locale
  475. for which you want to do the check. The optional second parameter declares whether translation
  476. is fixed to the declared language or a lower set of translations can be used. If you have a text which
  477. can be returned for 'en' but not for 'en_US' you will normally get the translation returned, but by
  478. setting <code>$original</code> to true, <code>isTranslated()</code> will return false.
  479. </para>
  480. <example id="zend.translate.additional.istranslated.example">
  481. <title>Checking if a text is translatable</title>
  482. <programlisting role="php"><![CDATA[
  483. $english = array(
  484. 'message1' => 'Nachricht 1',
  485. 'message2' => 'Nachricht 2',
  486. 'message3' => 'Nachricht 3');
  487. $translate = new Zend_Translate('array', $english, 'de_AT');
  488. if ($translate->isTranslated('message1')) {
  489. print "'message1' can be translated";
  490. }
  491. if (!($translate->isTranslated('message1', true, 'de'))) {
  492. print "'message1' can not be translated to 'de'"
  493. . " as it's available only in 'de_AT'";
  494. }
  495. if ($translate->isTranslated('message1', false, 'de')) {
  496. print "'message1' can be translated in 'de_AT' as it falls back to 'de'";
  497. }
  498. ]]></programlisting>
  499. </example>
  500. </sect2>
  501. <sect2 id="zend.translate.additional.logging">
  502. <title>How to log not found translations</title>
  503. <para>
  504. When you have a bigger site or you are creating the translation files manually, you often have
  505. the problem that some messages are not translated. But there is an easy solution for you when you
  506. are using <classname>Zend_Translate</classname>.
  507. </para>
  508. <para>
  509. You have to follow two or three simple steps. First, you have to create an instance of
  510. <classname>Zend_Log</classname>. Then you have to attach this instance to <classname>Zend_Translate</classname>.
  511. See the following example:
  512. </para>
  513. <example id="zend.translate.additional.logging.example">
  514. <title>Log translations</title>
  515. <programlisting role="php"><![CDATA[
  516. $translate = new Zend_Translate('gettext', $path, 'de');
  517. // Create a log instance
  518. $writer = new Zend_Log_Writer_Stream('/path/to/file.log');
  519. $log = new Zend_Log($writer);
  520. // Attach it to the translation instance
  521. $translate->setOptions(array(
  522. 'log' => $log,
  523. 'logUntranslated' => true));
  524. $translate->translate('unknown string');
  525. ]]></programlisting>
  526. </example>
  527. <para>
  528. Now you will have a new notice in the log: <code>Untranslated message within 'de': unknown string</code>.
  529. </para>
  530. <note>
  531. <para>
  532. You should note that any translation which can not be found will be logged. This means
  533. all translations when a user requests a language which is not supported. Also every request
  534. for a message which can not be translated will be logged. Be aware, that 100 people
  535. requesting the same translation, will result 100 logged notices.
  536. </para>
  537. </note>
  538. <para>
  539. This feature can not only be used to log messages but also to attach this untranslated messages
  540. into an empty translation file. To do so you will have to write your own log writer which
  541. writes the format you want to have and strips the prepending "Untranslated message".
  542. </para>
  543. <para>
  544. You can also set the '<code>logMessage</code>' option when you want to have your own log message.
  545. Use the '<code>%message%</code>' token for placing the messageId within your log message, and the
  546. '<code>%locale%</code>' token for the requested locale. See the following example for a self
  547. defined log message:
  548. </para>
  549. <example id="zend.translate.additional.logging.example2">
  550. <title>Self defined log messages</title>
  551. <programlisting role="php"><![CDATA[
  552. $translate = new Zend_Translate('gettext', $path, 'de');
  553. // Create a log instance
  554. $writer = new Zend_Log_Writer_Stream('/path/to/file.log');
  555. $log = new Zend_Log($writer);
  556. // Attach it to the translation instance
  557. $translate->setOptions(array(
  558. 'log' => $log,
  559. 'logMessage' => "Missing '%message%' within locale '%locale%'",
  560. 'logUntranslated' => true));
  561. $translate->translate('unknown string');
  562. ]]></programlisting>
  563. </example>
  564. </sect2>
  565. <sect2 id="zend.translate.additional.sourcedata">
  566. <title>Accessing source data</title>
  567. <para>
  568. Sometimes it is useful to have access to the translation source data. Therefor
  569. the following two functions are provided.
  570. </para>
  571. <para>
  572. The <code>getMessageIds($locale = null)</code> method returns all known message IDs as array.
  573. </para>
  574. <para>
  575. The <code>getMessages($locale = null)</code> method returns the complete translation source as
  576. an array. The message ID is used as key and the translation data as value.
  577. </para>
  578. <para>
  579. Both methods accept an optional parameter <code>$locale</code> which, if set, returns the
  580. translation data for the specified language. If this parameter is not given, the actual set
  581. language will be used. Keep in mind that normally all translations should be available in all
  582. languages. Which means that in a normal situation you will not have to set this parameter.
  583. </para>
  584. <para>
  585. Additionally the <code>getMessages()</code> method can be used to return the complete
  586. translation dictionary using the pseudo-locale 'all'. This will return all available
  587. translation data for each added locale.
  588. </para>
  589. <note>
  590. <para>
  591. Attention: the returned array can be <emphasis>very big</emphasis>,
  592. depending on the number of added locales and the amount of translation data.
  593. </para>
  594. </note>
  595. <example id="zend.translate.additional.sourcedata.example">
  596. <title>Handling languages with adapters</title>
  597. <programlisting role="php"><![CDATA[
  598. // returns all known message IDs
  599. $messageIds = $translate->getMessageIds();
  600. print_r($messageIds);
  601. // or just for the specified language
  602. $messageIds = $translate->getMessageIds('en_US');
  603. print_r($messageIds);
  604. // returns all the complete translation data
  605. $source = $translate->getMessages();
  606. print_r($source);
  607. ]]></programlisting>
  608. </example>
  609. </sect2>
  610. </sect1>
  611. <!--
  612. vim:se ts=4 sw=4 et:
  613. -->