Skip to content

Instantly share code, notes, and snippets.

@gsans
Last active August 29, 2015 14:10
Show Gist options
  • Save gsans/84d783ad514e20fda82a to your computer and use it in GitHub Desktop.
Save gsans/84d783ad514e20fda82a to your computer and use it in GitHub Desktop.
//language module
angular.module(‘myapp.language’, [‘pascalprecht.translate’])
.config(function($httpProvider, $translateProvider) {
… //seen before
})
// Service definition
.factory(‘Language’, function ($translate) {
//add the languages you support here. ar stands for arabic
var rtlLanguages = [‘ar’];
var isRtl = function() {
var languageKey = $translate.proposedLanguage() || $translate.use();
for (var i=0; i<rtlLanguages.length; i+=1) {
// You may need to change this logic depending on your supported languages (possible languageKey values)
// This code will match both "ar", "ar-XXX" locales. It won't match any other languages as we only support en, es, ar.
if (languageKey.indexOf(rtlLanguages[i])>-1)
return true;
}
return false;
};
//public api
return {
isRtl: isRtl
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment