Skip to content

Commit 84b988b

Browse files
committed
added localized texts
1 parent 486d4eb commit 84b988b

File tree

10 files changed

+72
-205
lines changed

10 files changed

+72
-205
lines changed

dist/index.html

Lines changed: 0 additions & 37 deletions
This file was deleted.

dist/index.html.gz

-614 Bytes
Binary file not shown.

dist/rapipdf-min.js

Lines changed: 0 additions & 55 deletions
This file was deleted.

dist/rapipdf-min.js.gz

-1 MB
Binary file not shown.

dist/rapipdf-min.js.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

dist/rapipdf-min.js.map.gz

-150 Bytes
Binary file not shown.

dist/report.html

Lines changed: 0 additions & 64 deletions
This file was deleted.

src/rapipdf.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,33 @@ export default customElements.define('rapi-pdf', class RapiPdf extends HTMLEleme
160160
let includeSecurity = this.getAttribute('include-security')==='false'?false:true;
161161
let includeApiDetails = this.getAttribute('include-api-details')==='false'?false:true;
162162
let includeApiList = this.getAttribute('include-api-list')==='true'?true:false;
163+
let localize = {
164+
'index':'INDEX',
165+
'api':'API',
166+
'apiList':'API List',
167+
'apiReference':'API Reference',
168+
'apiVersion':'API Version',
169+
'contact':'CONTACT',
170+
'name':'NAME',
171+
'email':'EMAIL',
172+
'url':'URL',
173+
'termsOfService':'Terms of service',
174+
'securityAndAuthentication':'Security and Authentication',
175+
'securitySchemes':'SECURITY SCHEMES',
176+
'type':'TYPE',
177+
'description':'DESCRIPTION',
178+
'request':'REQUEST',
179+
'requestBody':'REQUEST BODY',
180+
'response':'RESPONSE',
181+
'responseModel':'RESPONSE MODEL',
182+
'statusCode':'STATUS CODE',
183+
'deprecated':'DEPRECATED',
184+
'allowed':'allowed',
185+
'pattern':'pattern',
186+
'parameters':'Parameters',
187+
'noRequestParameters': 'No request parameters',
188+
'method':'METHOD'
189+
}
163190

164191
let options = {
165192
pdfPrimaryColor,
@@ -173,7 +200,8 @@ export default customElements.define('rapi-pdf', class RapiPdf extends HTMLEleme
173200
includeToc,
174201
includeSecurity,
175202
includeApiDetails,
176-
includeApiList
203+
includeApiList,
204+
localize,
177205
}
178206
createPdf(this.specUrl, options);
179207
}

src/utils/pdf-gen-utils.js

Lines changed: 38 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,26 @@ import marked from 'marked';
22
import { getTypeInfo, schemaToModel, schemaToPdf, removeCircularReferences} from '@/utils/common-utils';
33

44
//Info Def
5-
export function getInfoDef(spec, bookTitle){
5+
export function getInfoDef(spec, bookTitle, localize){
66
let content;
77
if (spec.info){
88
let contactDef=[], contactName, contactEmail, contactUrl, termsOfService;
99

1010
if (spec.info.contact){
1111
if (spec.info.contact.name){
12-
contactName = {text:[{text:'Name: ', style:['b','small']}, {text:spec.info.contact.name, style:['small']}]};
12+
contactName = {text:[{text:`\n${localize.name}: `, style:['b','small']}, {text:spec.info.contact.name, style:['small']}]};
1313
}
1414
if (spec.info.contact.email){
15-
contactEmail = {text:[{text:'Email: ', style:['b','small']}, {text:spec.info.contact.email, style:['small']}]};
15+
contactEmail = {text:[{text:`\n${localize.email}: `, style:['b','small']}, {text:spec.info.contact.email, style:['small']}]};
1616
}
1717
if (spec.info.contact.url){
18-
contactUrl = {text:[{text:'URL: ', style:['b','small']}, {text:spec.info.contact.url, style:['small','blue'],link:spec.info.contact.url}]};
18+
contactUrl = {text:[{text:`\n${localize.url}: `, style:['b','small']}, {text:spec.info.contact.url, style:['small','blue'],link:spec.info.contact.url}]};
1919
}
2020
if (spec.info.termsOfService){
21-
termsOfService = {text:[{text:'\nTerms of service: ', style:['b','small']}, {text:spec.info.termsOfService, style:['small','blue'],link:spec.info.termsOfService}]};
21+
termsOfService = {text:[{text:`\n${localize.termsOfService}: `, style:['b','small']}, {text:spec.info.termsOfService, style:['small','blue'],link:spec.info.termsOfService}]};
2222
}
2323
contactDef= [
24-
{text:'CONTACT', style:['p', 'b', 'topMargin3']},
24+
{text:localize.contact, style:['p', 'b', 'topMargin3']},
2525
{text:[
2626
contactName,
2727
contactEmail,
@@ -44,9 +44,9 @@ export function getInfoDef(spec, bookTitle){
4444
}
4545

4646
content = [
47-
{text: bookTitle ? bookTitle:'API Reference', style:['h2', 'primary','right', 'b', 'topMargin1']},
47+
{text: bookTitle ? bookTitle:localize.apiReference, style:['h2', 'primary','right', 'b', 'topMargin1']},
4848
(spec.info.title ? {text:spec.info.title, style:['title', 'right']} : ''),
49-
(spec.info.version ? {text:`API Version: ${spec.info.version}`, style:['p','b', 'right', 'alternate']} : ''),
49+
(spec.info.version ? {text:`${localize.apiVersion}: ${spec.info.version}`, style:['p','b', 'right', 'alternate']} : ''),
5050
specInfDescrMarkDef,
5151
...contactDef,
5252
{text:'', pageBreak:'after'}
@@ -55,20 +55,20 @@ export function getInfoDef(spec, bookTitle){
5555
}
5656
else{
5757
content = [
58-
{text:bookTitle?bookTitle:'API Reference', style:['h1', 'bold', 'primary','right', 'topMargin1']}
58+
{text:bookTitle?bookTitle:apiVersion.apiReference, style:['h1', 'bold', 'primary','right', 'topMargin1']}
5959
];
6060
}
6161
return content;
6262
};
6363

6464
//Security Def
65-
export function getSecurityDef(spec, tableLayout){
65+
export function getSecurityDef(spec, tableLayout, localize){
6666
let content =[]
6767
if (spec.securitySchemes){
68-
content.push( {text:'Security and Authentication', style:['h3', 'b', 'primary','right', 'topMargin3']} );
69-
content.push({text:'SECURITY SCHEMES', style:['b','tableMargin']});
68+
content.push( {text:localize.securityAndAuthentication, style:['h3', 'b', 'primary','right', 'topMargin3']} );
69+
content.push({text:localize.securitySchemes, style:['b','tableMargin']});
7070
let tableContent = [
71-
[ {text: 'TYPE', style: ['small','b']}, {text: 'DESCRIPTION', style: ['small','b']} ]
71+
[ {text: localize.type, style: ['small','b']}, {text: localize.description, style: ['small','b']} ]
7272
];
7373
for (const key in spec.securitySchemes) {
7474
tableContent.push([
@@ -90,8 +90,7 @@ export function getSecurityDef(spec, tableLayout){
9090
};
9191

9292
// API details def
93-
export function getApiDef(spec, filterPath, sectionHeading, tableLayout){
94-
93+
export function getApiDef(spec, filterPath, sectionHeading, tableLayout, localize){
9594
let content =[{text: sectionHeading, style:['h2','b'],pageBreak:'before'}];
9695
let tagSeq=0;
9796

@@ -148,13 +147,12 @@ export function getApiDef(spec, filterPath, sectionHeading, tableLayout){
148147
const headerParams = path.parameters ? path.parameters.filter(param => param.in === 'header'):null;
149148
const cookieParams = path.parameters ? path.parameters.filter(param => param.in === 'cookie'):null;
150149

151-
const pathParamTableDef = getParameterTableDef(pathParams, 'path',tableLayout);
152-
const queryParamTableDef = getParameterTableDef(queryParams, 'query',tableLayout);
153-
const requestBodyTableDefs = getRequestBodyDef(path.requestBody, tableLayout);
154-
const headerParamTableDef = getParameterTableDef(headerParams, 'header',tableLayout);
155-
const cookieParamTableDef = getParameterTableDef(cookieParams, 'cookie',tableLayout);
156-
157-
operationContent.push({ text: 'REQUEST', style:['p', 'b', 'alternate'], margin:[0, 10, 0, 0]});
150+
const pathParamTableDef = getParameterTableDef(pathParams, 'path',tableLayout, localize);
151+
const queryParamTableDef = getParameterTableDef(queryParams, 'query',tableLayout, localize);
152+
const requestBodyTableDefs = getRequestBodyDef(path.requestBody, tableLayout, localize);
153+
const headerParamTableDef = getParameterTableDef(headerParams, 'header',tableLayout, localize);
154+
const cookieParamTableDef = getParameterTableDef(cookieParams, 'cookie',tableLayout, localize);
155+
operationContent.push({ text: localize.request, style:['p', 'b', 'alternate'], margin:[0, 10, 0, 0]});
158156
if (pathParamTableDef || queryParamTableDef || headerParamTableDef || cookieParamTableDef || requestBodyTableDefs){
159157
if (pathParamTableDef){
160158
requestSetDef.push(pathParamTableDef);
@@ -183,10 +181,8 @@ export function getApiDef(spec, filterPath, sectionHeading, tableLayout){
183181
stack:requestSetDef,
184182
margin:[10, 0, 0, 0]
185183
});
186-
187-
188-
let respDef = getResponseDef(path.responses, tableLayout)
189-
operationContent.push({ text: 'RESPONSE', style:['p', 'b', 'alternate'], margin:[0, 10, 0, 0]});
184+
let respDef = getResponseDef(path.responses, tableLayout, localize)
185+
operationContent.push({ text: localize.response, style:['p', 'b', 'alternate'], margin:[0, 10, 0, 0]});
190186
operationContent.push({
191187
stack:respDef,
192188
margin:[10, 5, 0, 5]
@@ -231,7 +227,7 @@ export function getApiDef(spec, filterPath, sectionHeading, tableLayout){
231227

232228

233229
//Request Body Def
234-
function getRequestBodyDef(requestBody, tableLayout){
230+
function getRequestBodyDef(requestBody, tableLayout, localize){
235231
if (!requestBody){
236232
return;
237233
}
@@ -242,7 +238,7 @@ function getRequestBodyDef(requestBody, tableLayout){
242238
let contentTypeObj = requestBody.content[contentType];
243239
let requestBodyTableDef;
244240
if ( (contentType.includes('form') || contentType.includes('multipart-form')) && contentTypeObj.schema ){
245-
formParamTableDef = getParameterTableDef(contentTypeObj.schema.properties, "FORM DATA", tableLayout);
241+
formParamTableDef = getParameterTableDef(contentTypeObj.schema.properties, "FORM DATA", tableLayout, localize);
246242
content.push(formParamTableDef);
247243
}
248244
else{
@@ -259,7 +255,7 @@ function getRequestBodyDef(requestBody, tableLayout){
259255
table: {
260256
widths:['*'],
261257
body: [
262-
[{text:'REQUEST BODY '+ contentType, style:['small','b']}],
258+
[{text:`${localize.requestBody} ${contentType}`, style:['small','b']}],
263259
requestBodyTableDef
264260
]
265261
}
@@ -276,16 +272,16 @@ function getRequestBodyDef(requestBody, tableLayout){
276272
}
277273

278274
//Parameter Table
279-
function getParameterTableDef(parameters, paramType, tableLayout){
275+
function getParameterTableDef(parameters, paramType, tableLayout, localize){
280276
//let filteredParams= parameters ? parameters.filter(param => param.in === paramType):[];
281277
if (parameters.length == 0 ){
282278
return;
283279
}
284280
let tableContent = [
285281
[
286-
{text: 'NAME', style: ['sub','b','alternate']},
287-
{text: 'TYPE', style: ['sub','b','alternate']},
288-
{text: 'DESCRIPTION', style: ['sub','b','alternate']}
282+
{text: localize.name, style: ['sub','b','alternate']},
283+
{text: localize.type, style: ['sub','b','alternate']},
284+
{text: localize.description, style: ['sub','b','alternate']}
289285
]
290286
];
291287

@@ -314,19 +310,19 @@ function getParameterTableDef(parameters, paramType, tableLayout){
314310
text:[
315311
{text:paramSchema.required?'*':'', style:['small','b','red','mono'] },
316312
{text:param.name, style:['small','mono'] },
317-
(paramSchema.depricated ?{text:'\nDEPRICATED',style:['small','red','b'] }:undefined)
313+
(paramSchema.depricated ?{text:'\n'+localize.deprecated, style:['small','red','b'] }:undefined)
318314
]
319315
},
320316
{
321317
stack:[
322318
{ text: `${paramSchema.type==='array' ? paramSchema.arrayType:paramSchema.type}${paramSchema.format ? `(${paramSchema.format})`:'' }`, style:['small','mono']},
323319
( paramSchema.constrain ? { text: paramSchema.constrain, style:['small', 'gray']}:''),
324320
( paramSchema.allowedValues ? { text:[
325-
{text: 'allowed: ', style:['b','small']},
321+
{text: localize.allowed+': ', style:['b','small']},
326322
{text: paramSchema.allowedValues, style:['small', 'gray']}
327323
]} : ''
328324
),
329-
( paramSchema.pattern ? { text: `pattern: ${paramSchema.pattern}`, style:['small','gray']}:''),
325+
( paramSchema.pattern ? { text: `${localize.pattern}: ${paramSchema.pattern}`, style:['small','gray']}:''),
330326
]
331327
},
332328
{ text:param.description, style:['small'],margin:[0,2,0,0]},
@@ -335,7 +331,7 @@ function getParameterTableDef(parameters, paramType, tableLayout){
335331
}
336332

337333
return [
338-
{text: `${paramType} Parameters`.toUpperCase(), style:['small', 'b'], margin:[0,10,0,0]},
334+
{text: `${paramType} ${localize.parameters}`.toUpperCase(), style:['small', 'b'], margin:[0,10,0,0]},
339335
{
340336
table: {
341337
headerRows: 1,
@@ -351,7 +347,7 @@ function getParameterTableDef(parameters, paramType, tableLayout){
351347
}
352348

353349
//Response Def
354-
function getResponseDef(responses, tableLayout){
350+
function getResponseDef(responses, tableLayout, localize){
355351
let respDef=[];
356352
let allResponseModelTabelDefs=[];
357353
for(let statusCode in responses) {
@@ -370,7 +366,7 @@ function getResponseDef(responses, tableLayout){
370366
table: {
371367
widths:['*'],
372368
body: [
373-
[{text:`RESPONSE MODEL (${contentType})`,style:['small','b']}],
369+
[{text:`${localize.responseModel} (${contentType})`,style:['small','b']}],
374370
reponseModelTableDef
375371
]
376372
}
@@ -382,7 +378,7 @@ function getResponseDef(responses, tableLayout){
382378

383379
respDef.push({
384380
text:[
385-
{text: `STATUS CODE - ${statusCode}: `, style:['small', 'b']},
381+
{text: `${localize.statusCode} - ${statusCode}: `, style:['small', 'b']},
386382
{text: responses[statusCode].description, style:['small']}
387383
],
388384
margin:[0,10,0,0]
@@ -396,11 +392,11 @@ function getResponseDef(responses, tableLayout){
396392
}
397393

398394
//API List Def
399-
export function getApiListDef(spec, sectionHeading, tableLayout) {
395+
export function getApiListDef(spec, sectionHeading, tableLayout, localize) {
400396
let content =[{text: sectionHeading, style:['h3','b'],pageBreak:'before'}];
401397
spec.tags.map(function(tag, i){
402398
let tableContent = [
403-
[ {text: 'METHOD', style: ['small','b']}, {text: 'API', style: ['small','b']}]
399+
[ {text: localize.method, style: ['small','b']}, {text: localize.api, style: ['small','b']}]
404400
];
405401

406402
tag.paths.map(function(path){

src/utils/pdf-gen.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@ export default async function createPdf(specUrl, options){
6464
let allContent=[], infoDef={}, tocDef={}, securityDef={}, apiListDef={}, apiDef={};
6565

6666
if (options.includeInfo){
67-
infoDef = getInfoDef(parsedSpec, options.pdfTitle);
67+
infoDef = getInfoDef(parsedSpec, options.pdfTitle, options.localize);
6868
allContent.push(infoDef);
6969
}
7070
if (options.includeToc){
7171
tocDef = {
7272
toc: {
73-
title: {text: 'INDEX', style:['b', 'h2']},
73+
title: {text: options.localize.index, style:['b', 'h2']},
7474
numberStyle: {bold: true},
7575
style:['small'],
7676
},
@@ -79,15 +79,15 @@ export default async function createPdf(specUrl, options){
7979
allContent.push(tocDef);
8080
}
8181
if (options.includeSecurity){
82-
securityDef = getSecurityDef(parsedSpec, rowLinesTableLayout);
82+
securityDef = getSecurityDef(parsedSpec, rowLinesTableLayout, options.localize);
8383
allContent.push(securityDef);
8484
}
8585
if (options.includeApiDetails){
86-
apiDef = getApiDef(parsedSpec, '', 'API', rowLinesTableLayout, rowLinesOnlyTableLayout);
86+
apiDef = getApiDef(parsedSpec, '', options.localize.api, rowLinesTableLayout, options.localize);
8787
allContent.push(apiDef);
8888
}
8989
if (options.includeApiList){
90-
apiListDef =getApiListDef(parsedSpec, 'API List', rowLinesTableLayout);
90+
apiListDef = getApiListDef(parsedSpec, options.localize.apiList, rowLinesTableLayout, options.localize);
9191
allContent.push(apiListDef);
9292
}
9393

0 commit comments

Comments
 (0)