Changeset 10941
- Timestamp:
- 08/19/08 00:23:09 (5 years ago)
- Files:
-
- plugins/ysfR3Plugin/branches/1.1/README (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/ysfR3Plugin/branches/1.1/README
r9332 r10941 1 = ysfR3Plugin - A precompiled translation system for the symfony framework = 1 ysfR3Plugin 2 =========== 2 3 3 4 ysfR3Plugin allows you to integrate the symfony project with the Yahoo R3 project. Yahoo! r3 is an extensible open-source tool for building and maintaining variant web sites by creating, managing and localizing templates and translations. It can be controlled using both web and command line interfaces which generate text based files for use in internationalized applications. These outputs may take the form of templates, configuration files or even source code. r3 can save and load translation data in XLIFF format. It can be extended using Stickleback, a unique and powerful plugin engine. It can also be embedded into third party applications. If you are managing a website across multiple locations (e.g. the US, the UK and Japan), then you face the challenge of accommodating each location's language and possible page layout requirements. The ideal is to reuse common components as much as possible, and still allow room for differentiation. … … 5 6 R3 integration works by adding a precompile stage to templates/configurations where you can use special r3 markup tags, as well as use the r3 translation store to power symfony's built in i18n system (__()). 6 7 7 '''For more information about r3, please see http://developer.yahoo.com/r3/ and http://www.openr3.com/.''' 8 9 10 == Getting Started == 11 12 === Requirements === 13 14 '''ysfR3Plugin uses APC by default and it should be enabled in the command line. In addition, ysfR3Plugin is designed to be used in conjunction with the ysfDimensionsPlugin to provide complete i18n capabilities to symfony.''' 15 16 17 === Installation === 18 19 '''1. Install r3 (and dependencies) via pear''' 20 21 {{{ 22 pear install --alldeps r3 stickleback 23 }}} 24 25 '''2. Install and configure ysfDimensionsPlugin''' 26 27 {{{ 28 symfony plugin:install ysfDimensionsPlugin 29 }}} 30 31 32 '''3. Install the plugin via the symfony cli''' 33 34 {{{ 35 symfony plugin:install ysfR3Plugin 36 }}} 37 38 '''4. Clear symfony cache''' 39 40 {{{ 41 symfony cache:clear 42 }}} 43 44 45 === Configuration === 46 47 '''1. Configure your application configuration to use this plugin''' 48 49 {{{ 50 // manually require class since not part of symfony core 51 require_once(dirname(__FILE__).'/../../../plugins/ysfR3Plugin/lib/config/ysfR3ApplicationConfiguration.class.php'); 52 }}} 53 54 Edit apps/example/config/exampleConfiguration.class.php changing the parent class from sfApplicationConfiguration to '''ysfR3ApplicationConfiguration'''. 8 *For more information about r3, please see (http://developer.yahoo.com/r3/) and (http://www.openr3.com/).* 9 10 11 Requirements 12 ------------ 13 14 *ysfR3Plugin uses APC by default and it should be enabled in the command line. In addition, ysfR3Plugin is designed to be used in conjunction with the ysfDimensionsPlugin to provide complete i18n capabilities to symfony.* 15 16 17 Installation 18 ------------ 19 20 *1. Install r3 (and dependencies) via pear* 21 22 pear install --alldeps r3 stickleback 23 24 25 *2. Install and configure ysfDimensionsPlugin* 26 27 symfony plugin:install ysfDimensionsPlugin 28 29 30 *3. Install the plugin via the symfony cli* 31 32 symfony plugin:install ysfR3Plugin 33 34 35 *4. Clear symfony cache* 36 37 symfony cache:clear 38 39 40 41 Configuration 42 ------------- 43 44 *1. Configure your application configuration to use this plugin* 45 46 47 // manually require class since not part of symfony core 48 require_once(dirname(__FILE__).'/../../../plugins/ysfR3Plugin/lib/config/ysfR3ApplicationConfiguration.class.php'); 49 50 Edit apps/example/config/exampleConfiguration.class.php changing the parent class from sfApplicationConfiguration to *ysfR3ApplicationConfiguration*. 55 51 56 52 Now that the i18n hooks are in place, you need to configure your application, by following the steps below: 57 53 58 '''2. Update i18n factory''' 54 *2. Update i18n factory* 59 55 60 56 First we need to define the i18n factory in factories.yml: 61 {{{ 62 all: 63 i18n: 64 class: ysfR3I18N 65 param: 66 source: R3 # i18n source 67 database: %SF_DATA_DIR%/i18n/r3 68 debug: off # debug mode enabled? 69 untranslated_prefix: "[t]" # prefix for untranslated strings 70 untranslated_suffix: "[/t]" # suffix for untranslated strings 71 default_culture: en_US 72 allowed_cultures: [ en_US, en_GB, es_ES, de_DE, fr_FR, it_IT ] # allowed cultures 73 translate_markup: r3:trans 74 cache: 75 class: sfAPCCache 57 58 59 all: 60 i18n: 61 class: ysfR3I18N 76 62 param: 77 automatic_cleaning_factor: 0 78 lifetime: 31556926 79 prefix: %SF_APP_DIR%/i18n 80 }}} 81 82 83 '''3. Clear symfony cache''' 84 85 {{{ 86 symfony cache:clear 87 }}} 63 source: R3 # i18n source 64 database: %SF_DATA_DIR%/i18n/r3 65 debug: off # debug mode enabled? 66 untranslated_prefix: "[t]" # prefix for untranslated strings 67 untranslated_suffix: "[/t]" # suffix for untranslated strings 68 default_culture: en_US 69 allowed_cultures: [ en_US, en_GB, es_ES, de_DE, fr_FR, it_IT ] # allowed cultures 70 translate_markup: r3:trans 71 cache: 72 class: sfAPCCache 73 param: 74 automatic_cleaning_factor: 0 75 lifetime: 31556926 76 prefix: %SF_APP_DIR%/i18n 77 78 79 *3. Clear symfony cache* 80 81 82 symfony cache:clear 83 88 84 89 85 There are some required parameters for the ysfR3I18n factory, primarily: source, database, and allowed_cultures. 90 86 91 == Examples == 87 Examples 88 -------- 92 89 93 90 So what's really going on here? Let's talk a little about each of these. 94 91 95 === Using r3 in templates === 92 Using r3 in templates 93 --------------------- 96 94 97 95 The r3 integration works like the native __() method. Unlike the __() method, … … 101 99 If we want to localize a string in a template: 102 100 103 Let's try internationalizing the apps/frontend/modules/demo/templates/testSuccess.php template: 104 105 {{{ 106 <h1><r3:trans>Hello World!</r3:trans></h1> 107 <p><r3:trans>We are in the test template now.</r3:trans></p> 108 }}} 109 110 111 '''When symfony looks for the template, r3 will translate the text in the r3:trans tags and create a 101 Let's try localizing the apps/frontend/modules/demo/templates/testSuccess.php template: 102 103 <h1><r3:trans>Hello World!</r3:trans></h1> 104 <p><r3:trans>We are in the test template now.</r3:trans></p> 105 106 107 *When symfony looks for the template, r3 will translate the text in the r3:trans tags and create a 112 108 localized cache template in project/cache/i18n/$culture/apps/frontend/modules/demo/templates/testSuccess.php. 113 On every subsequent request the translation will not occur and symfony will use the localized file.''' 114 115 116 === Using r3 in configuration files === 109 On every subsequent request the translation will not occur and symfony will use the localized file.* 110 111 112 Using r3 in configuration files 113 ------------------------------- 117 114 118 115 Now we just need to establish the setting itself. This is an app-level setting … … 120 117 apps/frontend/config/view.yml: 121 118 122 {{{ 123 default:124 metas:125 title: <r3:trans>My Example</r3:trans>126 keywords: <r3:trans>symfony</r3:trans>, <r3:trans>project</r3:trans>, <r3:trans>framework</r3:trans>127 }}} 128 129 130 === Updating translations via r3 message source === 119 120 default: 121 metas: 122 title: <r3:trans>My Example</r3:trans> 123 keywords: <r3:trans>symfony</r3:trans>, <r3:trans>project</r3:trans>, <r3:trans>framework</r3:trans> 124 125 126 Updating translations via r3 message source 127 ------------------------------------------- 131 128 132 129 apps/frontend/modules/demo/actions/actions.class.php 133 {{{ 134 <?php 135 136 public function executeTest() 137 { 138 $this->getI18n()->getMessageSource()->setCulture('fr'); 139 $this->getI18n()->getMessageSource()->update('My Example', 'Mon Exemple', ''); 140 141 return $this->renderText($this->getI18n()->__('My Example')); 142 } 143 }}} 130 131 132 <?php 133 134 public function executeTest() 135 { 136 $this->getI18n()->getMessageSource()->setCulture('fr'); 137 $this->getI18n()->getMessageSource()->update('My Example', 'Mon Exemple', ''); 138 139 return $this->renderText($this->getI18n()->__('My Example')); 140 } 141 144 142 145 143 Now try changing the culture to fr and see the results. 146 144 147 145 148 === Updating translations via xliff dictionaries === 146 Updating translations via xliff dictionaries 147 -------------------------------------------- 149 148 150 149 Export xliff with symfony cli: 151 {{{ 152 symfony i18n:export-xliff153 }}} 150 151 symfony i18n:export-xliff 152 154 153 155 154 Update xliff in data/i18n/messages.xml: 156 {{{ 157 <trans-unit id='123' approved='yes'> 158 <source>My Example</source> 159 <target>Mon Exemple</target> 160 </trans-unit> 161 }}} 155 156 157 <trans-unit id='123' approved='yes'> 158 <source>My Example</source> 159 <target>Mon Exemple</target> 160 </trans-unit> 161 162 162 163 163 Import xliff with symfony cli: 164 {{{ 165 symfony i18n:import-xliff 166 }}} 164 165 symfony i18n:import-xliff 167 166 168 167 Now try changing the culture to fr and see the results. 169 168 170 169 171 === Generating cache for all translations === 170 Generating cache for all translations 171 ------------------------------------- 172 172 173 173 Use symfony cli to translate entire project: 174 {{{ 175 symfony i18n:translate 176 }}} 174 175 176 symfony i18n:translate 177 177 178 178 179 You'll need to clear the cache. 179 180 180 181 181 == Performance == 182 Performance 183 ----------- 182 184 183 185 Installing the ysfR3Plugin adds overhead to your project in development. This is the cost … … 187 189 188 190 189 == Tests == 191 Tests 192 ----- 190 193 191 194 For a complete example of how to use and test applications with r3, … … 193 196 194 197 195 == License == 198 License 199 ------- 196 200 197 201 Please see the packaged LICENSE file for the details of the MIT license. 198 202 199 203 200 == Todo == 204 Todo 205 ---- 201 206 202 207 * Ajax inline edit (in-context) for translation updates