Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Gives you Episerver's language XML-files as a Javascript object to use in the browser.

Notifications You must be signed in to change notification settings

Epinova/Epinova.JsResourceHandler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Epinova.JsResourceHandler

Simple module to include Episerver resource files/translation files for use in JavaScript.

Example:

You have an XML-file /lang/myNiceFile.NO.xml. After installing this module, this is accessible via

<script src="http://yourhostname/jsl10n/myNiceFile">
</script>

It will look for myNiceFile.NO.xml if you're on the NO-based hostname. If you're on a host using Swedish, it will look for myNiceFile.SV.xml. If none of those exist, it'll simply look for myNiceFile.xml. If it has exactly one language node, that will be the root of the output object. If it has multiple languages in one file, the languages element will be the root.

The language files must be contained in /lang/, seen from your web project. This is the default location from which Episerver picks up stuff anyways.

The object it outputs is called jsl10n (window.jsl10n).

Append ?debug=true to the URL to get indented JSON for debugging/inspection purposes.

Example usages

Function translate

$(function() {
	var cuteTextNode = window.jsl10n.translate("articlePage/myCuteTextNode")
})

Function translate with fallback

$(function() {
	var cuteTextNode = window.jsl10n.translate("articlePage/myCuteTextNode") || "My Cute Text"
})

Direct object refrence

$(function() {
	var cuteTextNode = window.jsl10n.articlepage.myCuteTextNode;
})

Inject Angular language service

var translator = function () {
    return window.jsl10n;
};
yourApp.factory('translator', [translator]);

Then inject it into your controllers as translator.

About

Gives you Episerver's language XML-files as a Javascript object to use in the browser.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published