Skip to content

Commit

Permalink
feat(component-meta): extract wordings for i18n | bh | #2615
Browse files Browse the repository at this point in the history
  • Loading branch information
denyo committed Jan 22, 2024
1 parent 5ed87ae commit ce75254
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/component-meta/scripts/generateComponentMeta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ const generateComponentMeta = (): void => {
/** @deprecated use \`eventsMeta\` instead */
deprecatedEventNames?: string[]; // array of event names
hasAriaProp: boolean;
wordings?: string[];
hasObserveAttributes: boolean;
observedAttributes?: string[];
hasObserveChildren: boolean;
Expand Down Expand Up @@ -183,6 +184,7 @@ const generateComponentMeta = (): void => {
/** @deprecated use `eventsMeta` instead */
deprecatedEventNames?: string[]; // array of event names
hasAriaProp: boolean;
wordings?: string[];
hasObserveAttributes: boolean;
observedAttributes?: string[];
hasObserveChildren: boolean;
Expand Down Expand Up @@ -742,6 +744,18 @@ const generateComponentMeta = (): void => {
observedAttributes = eval(rawObservedAttributes);
}

// i18n wordings
const wordings = Array.from(source.matchAll(/>([A-Za-z \n]+?)<\//g))
.map(([, potentialWording]) => {
const wording = potentialWording.trim();
return wording.match(/[A-Za-z \n]+/) ? wording : '';
})
.filter(Boolean);

if (wordings.length) {
console.log(tagName);
}

result[tagName] = {
...(isDeprecated && { isDeprecated, deprecationMessage }),
...(isExperimental && { isExperimental }),
Expand Down Expand Up @@ -771,6 +785,7 @@ const generateComponentMeta = (): void => {
...(eventNames.length && { eventNames }),
...(deprecatedEventNames.length && { deprecatedEventNames }),
hasAriaProp,
...(wordings.length && { wordings }),
hasObserveAttributes,
...(observedAttributes.length && { observedAttributes }),
hasObserveChildren,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3381,6 +3381,9 @@ exports[`should match snapshot 1`] = `
"open",
],
"styling": "jss",
"wordings": [
"Dismiss flyout",
],
},
"p-flyout-navigation": {
"allowedPropValues": {
Expand Down Expand Up @@ -3462,6 +3465,9 @@ exports[`should match snapshot 1`] = `
},
},
"styling": "jss",
"wordings": [
"Dismiss flyout",
],
},
"p-flyout-navigation-item": {
"allowedPropValues": {
Expand Down Expand Up @@ -3504,6 +3510,9 @@ exports[`should match snapshot 1`] = `
"identifier",
],
"styling": "jss",
"wordings": [
"Back",
],
},
"p-grid": {
"allowedPropValues": {
Expand Down Expand Up @@ -5055,6 +5064,9 @@ exports[`should match snapshot 1`] = `
},
},
"styling": "jss",
"wordings": [
"Close notification",
],
},
"p-link": {
"allowedPropValues": {
Expand Down Expand Up @@ -7487,6 +7499,9 @@ exports[`should match snapshot 1`] = `
"open",
],
"styling": "jss",
"wordings": [
"Dismiss modal",
],
},
"p-model-signature": {
"allowedPropValues": {
Expand Down Expand Up @@ -7744,6 +7759,10 @@ exports[`should match snapshot 1`] = `
"name",
],
"styling": "jss",
"wordings": [
"Reset selection",
"No results found",
],
},
"p-multi-select-option": {
"allowedPropValues": {
Expand Down Expand Up @@ -8212,6 +8231,9 @@ exports[`should match snapshot 1`] = `
},
},
"styling": "jss",
"wordings": [
"More information",
],
},
"p-radio-button-wrapper": {
"allowedPropValues": {
Expand Down Expand Up @@ -9293,6 +9315,9 @@ exports[`should match snapshot 1`] = `
"p-select-wrapper",
],
"styling": "jss",
"wordings": [
"No results found",
],
},
"p-spinner": {
"allowedPropValues": {
Expand Down Expand Up @@ -11143,6 +11168,12 @@ exports[`should match snapshot 1`] = `
"requiredChild": "input type=text",
"requiredChildSelector": "input[type=text],input[type=number],input[type=email],input[type=tel],input[type=search],input[type=url],input[type=date],input[type=time],input[type=month],input[type=week],input[type=password]",
"styling": "jss",
"wordings": [
"Toggle password visibility",
"Search",
"Clear field",
"Locate me",
],
},
"p-text-list": {
"allowedPropValues": {
Expand Down Expand Up @@ -11450,6 +11481,9 @@ exports[`should match snapshot 1`] = `
"p-toast",
],
"styling": "jss",
"wordings": [
"Close notification message",
],
},
"p-wordmark": {
"allowedPropValues": {
Expand Down Expand Up @@ -11540,6 +11574,9 @@ exports[`should match snapshot 1`] = `
},
},
"styling": "jss",
"wordings": [
"Porsche",
],
},
}
`;

0 comments on commit ce75254

Please sign in to comment.