75 lines
2.5 KiB
JavaScript
75 lines
2.5 KiB
JavaScript
import {ng, ngDeps} from './vendor';
|
|
|
|
const ngModule = ng.module('vnCore', ngDeps);
|
|
ngModule.constant('moment', require('moment-timezone'));
|
|
export default ngModule;
|
|
|
|
/**
|
|
* Acts like native Module.component() function but merging component options
|
|
* with parent component options. This method establishes the $options property
|
|
* to the component controller class with the merged component options. To
|
|
* retrieve parent options, it reads the same property of the parent class, so
|
|
* for the parent options to be copied, it must have been declared using this
|
|
* same function. If any of the options (template, transclude, bindings ...) is
|
|
* redeclared in the child component, it has preference.
|
|
*
|
|
* @param {String} name Coponent name in camelCase
|
|
* @param {Object} options The component options
|
|
* @return {angularModule} The same angular module
|
|
*/
|
|
ngModule.vnComponent = function(name, options) {
|
|
let controller = options.controller;
|
|
let parent = Object.getPrototypeOf(controller);
|
|
let parentOptions = parent.$options || {};
|
|
|
|
let mergedOptions = Object.assign({},
|
|
parentOptions,
|
|
options,
|
|
{
|
|
transclude: Object.assign({},
|
|
parentOptions.transclude,
|
|
options.transclude
|
|
),
|
|
bindings: Object.assign({},
|
|
parentOptions.bindings,
|
|
options.bindings
|
|
)
|
|
}
|
|
);
|
|
controller.$options = mergedOptions;
|
|
|
|
return this.component(name, mergedOptions);
|
|
};
|
|
|
|
config.$inject = ['$translateProvider', '$translatePartialLoaderProvider'];
|
|
export function config($translateProvider, $translatePartialLoaderProvider) {
|
|
$translatePartialLoaderProvider.addPart('core');
|
|
|
|
let conf = {urlTemplate: '/locale/{part}/{lang}.json'};
|
|
|
|
let fallbackLang = 'es';
|
|
let langs = ['en', 'es'];
|
|
let langAliases = {
|
|
en_US: 'en',
|
|
en_UK: 'en',
|
|
es_ES: 'es',
|
|
es_AR: 'es'
|
|
};
|
|
|
|
$translateProvider
|
|
.useSanitizeValueStrategy('escape')
|
|
.useLoader('$translatePartialLoader', conf)
|
|
.registerAvailableLanguageKeys(langs, langAliases)
|
|
// FIXME: Circular dependency due to vnInterceptor
|
|
// .fallbackLanguage(fallbackLang)
|
|
.determinePreferredLanguage(() => {
|
|
let locale = $translateProvider.resolveClientLocale();
|
|
if (langs.indexOf(locale) !== -1)
|
|
return locale;
|
|
if (langAliases[locale])
|
|
return langAliases[locale];
|
|
return fallbackLang;
|
|
});
|
|
}
|
|
ngModule.config(config);
|