ForgeComponents
en

Components

j-Resource

jComponent 20 · jcomponent@20 component Example loaded with jComponent 20

Resources are very great solution for e.g. translate some texts in all scripts. The component can be appended multiple-times and all components use one repository for storing keys and values.


METHODS:

  • RESOURCE(key, [def]) - is a global method
  • FIND('resource').download('/my-dictionary.txt', [callback]); - for importing new resources

Use it with <ui-component name="resource">. When the component is not loaded yet, jComponent downloads it on first use from the address in DEF.fallback (the Componentator CDN by default). Author: Peter Širka. Source: the Componentator components repository, MIT license.

example.html
Open Web Developer console.

<ui-component name="resource">
	<script type="text/plain">
			yes     : Yes
			no      : No
			message : Are you sure?
	</script>
</ui-component>

<ui-component name="resource">
	<script type="text/plain">
			first     : Value of first
			second    : Value of second
			a b c     : ABC
	</script>
</ui-component>

<script>

	setTimeout(function() {
		console.log(RESOURCE('yes'));
		console.log(RESOURCE('no'));
		console.log(RESOURCE('message'));
		console.log(RESOURCE('first'));
		console.log(RESOURCE('second'));
		console.log(RESOURCE('a b c'));
		console.log(RESOURCE('notfound', 'NOT FOUND'));
	}, 2000);

</script>