|
| 1 | +# Best Practices for Localization & Internationalization |
| 2 | + |
| 3 | +## Table of Contents |
| 4 | + |
| 5 | +* [For Non-Componentized Projects](#for-non-componentized-projects) |
| 6 | +* [For Componentized Projects](#for-componentized-projects) |
| 7 | +* [Best Practices for Theming](#best-practices-for-theming) |
| 8 | + |
| 9 | + |
| 10 | +Otherwise known as l10n and i18n, we sometimes must author CSS that targets certain nationalities. Below we describe two methodologies for tackling this particular challenge: |
| 11 | + |
| 12 | + |
| 13 | +## For Non-Componentized Projects |
| 14 | + |
| 15 | +Projects that don't follow Mobify's modern CSS best practices aren't likely to have component classes. As such, targeting changes is most likely going to be entirely through template class names and desktop class names. |
| 16 | + |
| 17 | +As such, our preferred method for apply l10n and i18n styles is as follows. |
| 18 | + |
| 19 | +1. Create a localization or internationalization folder |
| 20 | +2. Create a SCSS file for each l10n or i18n that is to be targetted (i.e. english, french, deutch, etc.) |
| 21 | +3. Write your SCSS in the following format... |
| 22 | + |
| 23 | +```scss |
| 24 | +.x-deutsch { |
| 25 | + |
| 26 | + .t-template-name { |
| 27 | + // ... |
| 28 | + } |
| 29 | + |
| 30 | + .client-class-name { |
| 31 | + // ... |
| 32 | + } |
| 33 | +} |
| 34 | +``` |
| 35 | + |
| 36 | + |
| 37 | +## For Componentized Projects |
| 38 | + |
| 39 | +Projects that do follow Mobify's modern CSS best practices have component classes. As such, our preferred method of applying l10n and i18n changes is as follows. |
| 40 | + |
| 41 | +1. Identify whether a l10n or i18n change applies to a component or template class |
| 42 | +2. Open that component or class in your editor |
| 43 | +3. Apply the l10n or i18n change in the same way we treat global state classes (see below) |
| 44 | + |
| 45 | +```scss |
| 46 | +// If it's a component class |
| 47 | +.c-component-name { |
| 48 | + |
| 49 | + .x-deutsch & { |
| 50 | + // ... |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +.c-component-name__sub-component { |
| 55 | + |
| 56 | + .x-deutsch & { |
| 57 | + // ... |
| 58 | + } |
| 59 | +} |
| 60 | + |
| 61 | + |
| 62 | +// If it's a template class... |
| 63 | +.t-page-name { |
| 64 | + |
| 65 | + .x-deutsch & { |
| 66 | + // ... |
| 67 | + |
| 68 | + .desktop-class { |
| 69 | + // ... |
| 70 | + } |
| 71 | + |
| 72 | + .more-desktop-classes { |
| 73 | + // ... |
| 74 | + } |
| 75 | + } |
| 76 | +} |
| 77 | + |
| 78 | +.t-page-name__sub-template { |
| 79 | + |
| 80 | + .x-deutsch { |
| 81 | + // ... |
| 82 | + } |
| 83 | +} |
| 84 | +``` |
| 85 | + |
| 86 | + |
| 87 | +## Best Practices for Theming |
| 88 | + |
| 89 | +When creating theme styles, it is best practice to... |
| 90 | + |
| 91 | +1. Create a themes.scss in the /scss directory |
| 92 | +2. Create a /theme directory, in which you will... |
| 93 | +3. Create the following directory: /component, /templates, and any other directories you deem necessary |
| 94 | + |
| 95 | +So your newly created files and directories should look like the follow (existing files excluded): |
| 96 | + |
| 97 | + |
| 98 | +``` |
| 99 | +/scss |
| 100 | + themes.scss |
| 101 | + /themes |
| 102 | + /components |
| 103 | + /templates |
| 104 | +``` |
| 105 | + |
| 106 | +Any theme styles you write should go in their appropriate directory in /themes. For example, if a product-list component is themed, it would belong in `/scss/themes/components/_product-list.scss`. |
| 107 | + |
| 108 | +Any SCSS files created in the /themes directory should be formatted as follows: |
| 109 | + |
| 110 | +```scss |
| 111 | +// In the case of component styles... |
| 112 | +.x-theme-class-name { |
| 113 | + |
| 114 | + .c-component-class-name { |
| 115 | + // ... |
| 116 | + } |
| 117 | +} |
| 118 | + |
| 119 | + |
| 120 | +// In the case of template styles |
| 121 | +.x-theme-class-name { |
| 122 | + |
| 123 | + .t-template-class-name { |
| 124 | + // ... |
| 125 | + } |
| 126 | +} |
| 127 | +``` |
| 128 | + |
| 129 | +The .x-theme-class-name is basically a global state that we are expecting to be applied on either the HTML, body, or other top level container. |
| 130 | + |
| 131 | +Continue on to [Block Comment Documentation Guide →](../comments/Readme.md) |
0 commit comments