-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathModuleConfig.cfc
125 lines (115 loc) · 4.11 KB
/
ModuleConfig.cfc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/**
* ********************************************************************************
* Copyright Since 2005 ColdBox Framework by Luis Majano and Ortus Solutions, Corp
* www.ortussolutions.com
* *******************************************************************************
*/
component {
// Module Properties
this.title = "cbi18n";
this.author = "Luis Majano";
this.webURL = "https://www.ortussolutions.com";
this.description = "Gives i18n and localization capabilities to applications";
this.version = "@build.version@[email protected]@";
// Model Namespace
this.modelNamespace = "cbi18n";
// CF Mapping
this.cfmapping = "cbi18n";
// Helpers
this.applicationHelper = [ "helpers/Mixins.cfm" ];
// Dependencies
this.dependencies = [ "cbstorages" ];
/**
* Configure Module
*/
function configure(){
settings = {
// The default resource to load and aliased as `default`
"defaultResourceBundle" : "",
// The locale to use when none defined
"defaultLocale" : "en_US",
// The default storage for the locale
"localeStorage" : "cookieStorage@cbstorages",
// What to emit to via the resource methods if a translation is not found
"unknownTranslation" : "",
// If true, we will log to LogBox the missing translations
"logUnknownTranslation" : false,
// Boolean marker indicating if the module has loaded resources and the i18n model needs to load, mostly used internally
"using_i18N" : false,
// A-la-carte resources to load by name
"resourceBundles" : {},
// You can override the ResourceService with your own, just add the WireBox ID
"customResourceService" : ""
};
// Emitted Events
interceptorSettings = { customInterceptionPoints : "onUnknownTranslation" };
}
/**
* Fired when the module is registered and activated.
*/
function onLoad(){
// Remap Resource Service if settings allow it
if ( variables.settings.customResourceService.len() ) {
binder
.map( alias: "resourceService@cbi18n", force: true )
.to( variables.settings.customResourceService );
}
}
/**
* Fired when the module is unregistered and unloaded
*/
function onUnload(){
}
/**
* Listen when modules are activated to load their i18n capabilities
*/
function afterAspectsLoad( event, interceptData ){
var modules = controller.getSetting( "modules" );
var moduleService = controller.getModuleService();
var moduleConfigCache = moduleService.getModuleConfigCache();
modules.each( function( thisModule ){
// get module config object
var oConfig = moduleConfigCache[ arguments.thisModule ];
// Get module settings and see if it uses cbi18n
var moduleSettings = oConfig.getPropertyMixin( "cbi18n", "variables", {} );
if ( structCount( moduleSettings ) ) {
var flagi18n = false;
// set defaults
modules[ arguments.thisModule ].cbi18n = {
defaultResourceBundle : "",
defaultLocale : "",
localeStorage : "cookieStorage@cbstorages",
unknownTranslation : "",
logUnknownTranslation : false,
resourceBundles : {},
customResourceService : ""
};
// append incoming settings
structAppend(
modules[ arguments.thisModule ].cbi18n,
moduleSettings,
true
);
// process settings, only set if not there yet.
var keys = "defaultResourceBundle,unknownTranslation,defaultLocale,localeStorage";
keys.listEach( function( element, index, list ){
if ( modules[ thisModule ][ "cbi18n" ][ element ].len() && !settings[ element ].len() ) {
settings[ element ] = modules[ thisModule ][ "cbi18n" ][ element ];
flagi18n = true;
}
} );
if ( structCount( modules[ arguments.thisModule ].cbi18n.resourceBundles ) ) {
settings.resourceBundles.append( modules[ arguments.thisModule ].cbi18n.resourceBundles, true );
flagi18n = true;
}
if ( flagi18n ) {
settings.using_i18N = true;
}
};
} );
// startup the i18n engine if using it, else ignore.
if ( settings.using_i18N ) {
wirebox.getInstance( "i18n@cbi18n" );
};
};
}