@@ -116,26 +116,29 @@ module.exports = fp(async (fastify, options) => {
116116 } ;
117117
118118 if ( ! fastify . hasDecorator ( options . name ) ) {
119- const defaultIntl = await createIntlInstance ( options . defaultLocale , options . moduleName ) ;
120- const defaultT = ( id , values ) => {
121- return defaultIntl . formatMessage ( { id } , values ) ;
122- } ;
123119 fastify . register ( require ( '@kne/fastify-namespace' ) , {
124120 name : options . name ,
125121 options,
126122 modules : [
127123 [ 'createIntl' , createIntlInstance ] ,
128124 [ 'getRequestLocale' , getRequestLocale ] ,
129125 [ 'withLocale' , withLocale ] ,
130- [ 'defaultIntl' , defaultIntl ] ,
131- [ 't' , defaultT ]
126+ [
127+ 't' ,
128+ ( id , values ) => {
129+ return fastify [ options . name ] . defaultIntl . formatMessage ( { id } , values ) ;
130+ }
131+ ]
132132 ] ,
133- onMount : name => {
133+ onMount : async name => {
134134 if ( name === options . name ) {
135135 return ;
136136 }
137137 const locale = fastify . namespace . modules ?. [ name ] ?. locale ;
138138 locale && loadMessage ( locale , name ) ;
139+ if ( name === options . moduleName ) {
140+ fastify [ options . name ] . defaultIntl = await createIntlInstance ( options . defaultLocale , options . moduleName ) ;
141+ }
139142 }
140143 } ) ;
141144 fastify . addHook ( 'onRequest' , async request => {
0 commit comments