Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENYO-6104: Add i18n to starter theme #3

Open
wants to merge 36 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
ad03570
add MyThemeDecorator and supporting bits
Jun 20, 2019
cf21b83
add initial BodyText component
Jun 20, 2019
f0694c4
add initial Heading component
Jun 20, 2019
f0d043f
update README
Jun 20, 2019
067d6b8
put skins.less in correct order
Jun 20, 2019
e4e2ddd
add initial Button and Icon components
Jun 20, 2019
df8c82a
add initial Item component
Jun 25, 2019
074d759
add initial SlotItem component
Jun 25, 2019
5e4bac6
add initial ToggleIcon and ToggleItem components
Jun 25, 2019
a4c1658
add initial Checkbox and RadioItem components
Jun 25, 2019
3d3579a
Switched to a more stanardized name "ThemeDecorator"
Jun 25, 2019
c72a02d
Updated readme with new decorator name
Jun 25, 2019
0a3a668
require Enact 3.0.0+
Jun 26, 2019
c4779af
add initial Panels and Panel components
Jun 26, 2019
8c44203
fixup Panel
Jun 26, 2019
fe2988b
Updated BodyText and Button style variables
Jun 26, 2019
9721182
Fix theme modularity
Jun 26, 2019
131a043
Styling updates
Jun 27, 2019
d170a3e
Updated Panels, general style, and Added Checkbox. Refactored RadioItem
Jun 28, 2019
e743446
Small Buttons!
Jun 28, 2019
a07fd65
Added some inline skin.less docs
Jul 1, 2019
5c266ab
update README
Jul 2, 2019
06a8bdc
another README update
Jul 2, 2019
55bbaa4
No muted, better decorator docs, no useless bodytext center, fixed rt…
Jul 2, 2019
b3db4db
Dropped Pure
Jul 2, 2019
eead945
Bit of rearrangement of Button LESS
Jul 2, 2019
d2de9dc
remove extraneous props from Panels and Panel
Jul 2, 2019
3d34ad2
let the Panels content be seen!
Jul 2, 2019
0503a61
Converted Icon to material icons
Jul 2, 2019
9d75a11
update README again
Jul 2, 2019
842424e
Removal of moonstone references
Jul 3, 2019
2b4791e
add i18n to theme decorator
Jul 10, 2019
c5fdfa8
Merge branch 'develop' into feature/add-i18n
Jul 11, 2019
328c1b0
add missing i18n bits
Jul 18, 2019
7a3c0be
fixup
Jul 25, 2019
068186b
make ilib a peer and dev dependency
Jul 25, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@ Most of the components in the starter theme are built from base components provi
* `ToggleIcon` - an `Icon` with `ui/Toggleable` behavior
* `ToggleItem` - an `Item` with `ui/Toggleable` behavior

There is also an internal implementation for `$L` (an `ilib` translation module) that can be used by theme components to provide translations.

### Behaviors

The Enact framework has several modules that provide various behaviors. The starter theme applies the following behaviors to the wrapped app by default:

* Internationalization/localization - uses the [iLib](http://github.com/iLib-js/iLib) library to provide localized rendering
* Resolution independence - makes sure components are the same size (relative or not) on different screen resolutions
* Spotlight - spatial navigation with pointer or other input devices

Expand Down Expand Up @@ -55,9 +58,9 @@ git clone https://github.com/enactjs/my-theme.git uranium

### Rename

Globally replace instances of `my-theme` with the package name of your theme and instances of `MyTheme` with the name of your theme.
Globally replace instances of `my-theme` with the package name of your theme, instances of `MyTheme` with the name of your theme, and instances of `ILIB_MY_THEME_PATH`.

Following the "uranium" example, use `uranium` and `Uranium`, respectively.
Following the "uranium" example, use `uranium` and `Uranium`, and `ILIB_URANIUM_PATH` respectively.

Theme developers may also want to change the name of the default skin as part of the rename process. Globally replace `my-skin` with something else, such as `proton`, and update the `variables-my-skin.less` and `colors-my-skin.less` file names as appropriate.

Expand Down
7 changes: 5 additions & 2 deletions ThemeDecorator/ThemeDecorator.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
*/

import {addAll} from '@enact/core/keymap';
import kind from '@enact/core/kind';
import hoc from '@enact/core/hoc';
import I18nDecorator from '@enact/i18n/I18nDecorator';
import kind from '@enact/core/kind';
import React from 'react';
import {ResolutionDecorator} from '@enact/ui/resolution';
import {FloatingLayerDecorator} from '@enact/ui/FloatingLayer';
Expand All @@ -25,6 +26,7 @@ import css from './ThemeDecorator.module.less';
*/
const defaultConfig = {
float: true,
i18n: true,
noAutoFocus: false,
ri: {
screenTypes
Expand Down Expand Up @@ -53,13 +55,14 @@ const defaultConfig = {
* @public
*/
const ThemeDecorator = hoc(defaultConfig, (config, Wrapped) => {
const {float, noAutoFocus, ri, skin, spotlight} = config;
const {float, i18n, noAutoFocus, ri, skin, spotlight} = config;

const bgClassName = 'enact-fit';

let App = Wrapped;
if (float) App = FloatingLayerDecorator({wrappedClassName: bgClassName}, App);
if (ri) App = ResolutionDecorator(ri, App);
if (i18n) App = I18nDecorator(App);
if (spotlight) App = SpotlightRootDecorator({noAutoFocus}, App);
if (skin) App = Skinnable({defaultSkin: 'my-skin'}, App);

Expand Down
98 changes: 98 additions & 0 deletions internal/$L/$L.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/* global ILIB_MY_THEME_PATH */

import {getIStringFromBundle} from '@enact/i18n/src/resBundle';
import ResBundle from 'ilib/lib/ResBundle';

// The ilib.ResBundle for the active locale used by $L
let resBundle;

/**
* Returns the current ilib.ResBundle
*
* @returns {ilib.ResBundle} Current ResBundle
*/
function getResBundle () {
return resBundle;
}

/**
* Creates a new ilib.ResBundle for string translation
*
* @param {ilib.Locale} locale Locale for ResBundle
*
* @returns {Promise|ResBundle} Resolves with a new ilib.ResBundle
*/
function createResBundle (options) {
let opts = options;

if (typeof ILIB_MY_THEME_PATH !== 'undefined') {
opts = {
loadParams: {
root: ILIB_MY_THEME_PATH
},
...options
};
}

if (!opts.onLoad) return;

// eslint-disable-next-line no-new
new ResBundle({
...opts,
onLoad: (bundle) => {
opts.onLoad(bundle || null);
}
});
}

/**
* Deletes the current bundle object of strings and clears the cache.
* @returns {undefined}
*/
function clearResBundle () {
delete ResBundle.strings;
delete ResBundle.sysres;
resBundle = null;
}

/**
* Set the locale for the strings that $L loads. This may reload the
* string resources if necessary.
*
* @param {string} spec the locale specifier
* @returns {ilib.ResBundle} Current ResBundle
*/
function setResBundle (bundle) {
return (resBundle = bundle);
}

function toIString (str) {
let rb = getResBundle();

if (!rb) {
createResBundle({sync: true, onLoad: setResBundle});
}

return getIStringFromBundle(str, rb);
}

/**
* Maps a string or key/value object to a translated string for the current locale.
*
* @function
* @memberof i18n/$L
* @param {String|Object} str Source string
*
* @returns {String} The translated string
*/
function $L (str) {
return String(toIString(str));
}

export default $L;
export {
$L,
clearResBundle,
createResBundle,
setResBundle
};
3 changes: 3 additions & 0 deletions internal/$L/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"main": "$L.js"
}
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,11 @@
"prop-types": "^15.6.2",
"ramda": "^0.25.0",
"react": "^16.0.0"
},
"peerDependencies": {
"ilib": "^14.2.0"
},
"devDependencies": {
"ilib": "^14.2.0"
}
}
3 changes: 3 additions & 0 deletions resources/ilibmanifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"files": []
}