Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Commit dcc2c87

Browse files
committed
Merge pull request #53 from mobify/add-l10n-and-i18n-best-practices
Add new "Localization and Theming" section
2 parents 199f28c + 929d381 commit dcc2c87

File tree

4 files changed

+134
-1
lines changed

4 files changed

+134
-1
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
2.3.5
22
- Add Sass documentation about placeholders and `@extends`
3+
- Add CSS documentation on l10n and i18n best practices
34
2.3.4
45
- Patch CSSComb and scss-lint rules for compatibility
56
- LeadingZero aligned to enabled

css/Readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
* [When to use our selector naming scheme](class-naming-conventions#when-to-use-our-selector-naming-scheme)
4040
* [When to use their existing selectors](class-naming-conventions#when-to-use-their-existing-selectors)
4141
* [How to use their existing selectors in our components](class-naming-conventions#how-to-use-their-existing-selectors-in-our-components)
42+
* [Localization and Theming Best Practices](localization-and-theming-best-practices/readme.md)
4243
* [Block Comment Documentation Guide](comments/Readme.md)
4344
* [Hybrid Projects Best Practices](hybrid-projects/Readme.md)
4445

css/class-naming-conventions/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,4 +381,4 @@ Use their modifiers the same way you would use our modifiers. Chain it to the co
381381

382382
> If they use their modifiers in weird or unexpected ways, consider using the konf or templating to add our modifier classes instead.
383383
384-
Continue on to [Block Comment Documentation Guide →](../comments/Readme.md)
384+
Continue on to [Block Comment Documentation Guide →](../localization-and-theming-best-practices/readme.md)
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
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

Comments
 (0)