partial.js logo
Latest version
v1.3.1 (RC2)

How do resources work?


Resources serve for multi-language website. Are simple and effective.


Resource example



Resource definition

default.resource

key1           : value1

// comment
key2           : value2
key3           : <b>with the tag</b>

en.resource

key1           : value1-en

// comment
key2           : value2-en
key3           : <b>with the tag-en</b>

de.resource

key1           : value1-de

// comment
key2           : value2-de
key3           : <b>with the tag-de</b>

Read from resources

framework.resource()

Documentation: framework.resource()

console.log(framework.resource('key1'));
// value1

console.log(framework.resource('en', 'key1'));
// value1-en

console.log(framework.resource('de', 'key1'));
// value1-de

controller.resource()

Documentation: controller.resource()

console.log(controller.resource('key2'));
// value2

console.log(controller.resource('en', 'key2'));
// value2-en

console.log(controller.resource('de', 'key2'));
// value2-de

@{resource()}

Documentation: @{resource()}

@{resource('key3')}
<!-- Encoded: &lt;b&gt;with the tag&lt;/b&gt; -->

@{!resource('key3')}
<!-- Raw: <b>with the tag</b> -->

@{resource('en', 'key3')}
<!-- Encoded: &lt;b&gt;with the tag-en&lt;/b&gt; -->

@{!resource('en', 'key3')}
<!-- Raw: <b>with the tag-en</b> -->

@{resource('de', 'key3')}
<!-- Encoded: &lt;b&gt;with the tag-de&lt;/b&gt; -->

@{!resource('de', 'key3')}
<!-- Raw: <b>with the tag-de</b> -->