@@ -187,10 +187,22 @@ export class DOCXExporter<
187
187
] ;
188
188
}
189
189
190
- protected async createDefaultDocumentOptions ( ) : Promise < DocumentOptions > {
191
- const externalStyles = ( await import ( "./template/word/styles.xml?raw" ) )
190
+ protected async createDefaultDocumentOptions (
191
+ locale ?: string ,
192
+ ) : Promise < DocumentOptions > {
193
+ let externalStyles = ( await import ( "./template/word/styles.xml?raw" ) )
192
194
. default ;
193
195
196
+ // Replace the default language in styles.xml with the provided locale.
197
+ // If not provided, default to en-US.
198
+ const resolvedLocale = ( locale && locale . trim ( ) ) || "en-US" ;
199
+ // Replace w:lang w:val="..." with the desired locale, leaving other attributes intact
200
+ // This targets the run default language defined in styles.xml
201
+ externalStyles = externalStyles . replace (
202
+ / ( < w : l a n g \b [ ^ > ] * \b w : v a l = " ) ( [ ^ " ] + ) ( " [ ^ > ] * \/ > ) / g,
203
+ `$1${ resolvedLocale } $3` ,
204
+ ) ;
205
+
194
206
const bullets = [ "•" ] ; //, "◦", "▪"]; (these don't look great, just use solid bullet for now)
195
207
return {
196
208
numbering : {
@@ -247,6 +259,11 @@ export class DOCXExporter<
247
259
options : {
248
260
sectionOptions : Omit < ISectionOptions , "children" > ;
249
261
documentOptions : DocumentOptions ;
262
+ /**
263
+ * The document locale in OOXML format (e.g. en-US, fr-FR, de-DE).
264
+ * If omitted, defaults to en-US.
265
+ */
266
+ locale ?: string ;
250
267
} = {
251
268
sectionOptions : { } ,
252
269
documentOptions : { } ,
@@ -276,13 +293,18 @@ export class DOCXExporter<
276
293
options : {
277
294
sectionOptions : Omit < ISectionOptions , "children" > ;
278
295
documentOptions : DocumentOptions ;
296
+ /**
297
+ * The document locale in OOXML format (e.g. en-US, fr-FR, de-DE).
298
+ * If omitted, defaults to en-US.
299
+ */
300
+ locale ?: string ;
279
301
} = {
280
302
sectionOptions : { } ,
281
303
documentOptions : { } ,
282
304
} ,
283
305
) {
284
306
const doc = new Document ( {
285
- ...( await this . createDefaultDocumentOptions ( ) ) ,
307
+ ...( await this . createDefaultDocumentOptions ( options . locale ) ) ,
286
308
...options . documentOptions ,
287
309
sections : [
288
310
{
0 commit comments