Skip to content

Commit 85d55f0

Browse files
committed
Fixed method for retrieving locale data
1 parent 7053c5a commit 85d55f0

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

src/card.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,11 @@ function getAnimationStyles(
161161
* @returns {Promise<string>} - SVG markup for the statistics card.
162162
*/
163163
export default async function card(data: GetData, uiConfig: UiConfig): Promise<string> {
164-
const fallbackLocale = "en";
165-
const defaultLocale = locales[fallbackLocale];
166-
const selectedLocale = locales[uiConfig.Locale] || defaultLocale;
164+
const getLocale = (locale: string): string => {
165+
return Object.keys(locales).includes(locale) ? locale : "en";
166+
};
167+
const activeLocale = getLocale(uiConfig.Locale);
168+
const selectedLocale = locales[activeLocale];
167169

168170
const isRtl = parseBoolean(selectedLocale.rtlDirection || false);
169171
const isAnimDisabled = parseBoolean(uiConfig.disabledAnimations || uiConfig.Format === "png");
@@ -172,7 +174,7 @@ export default async function card(data: GetData, uiConfig: UiConfig): Promise<s
172174
// Card title
173175
let titleCard = (uiConfig.Title && uiConfig.Title !== "undefined")
174176
? uiConfig.Title.split("{name}").join(data.name)
175-
: (selectedLocale.titleCard || defaultLocale.titleCard).split("{name}").join(data.name);
177+
: (selectedLocale.titleCard).split("{name}").join(data.name);
176178

177179
// Profile picture process
178180
const photoQuality = Number(uiConfig.photoQuality || 80);
@@ -215,7 +217,7 @@ export default async function card(data: GetData, uiConfig: UiConfig): Promise<s
215217

216218
const visibleItems = itemsConfig.filter(item => item.visible);
217219
const cardItemsSVG = visibleItems.map((item, idx) => {
218-
const label = (selectedLocale as any)[item.labelKey] || (defaultLocale as any)[item.labelKey];
220+
const label = (selectedLocale as any)[item.labelKey];
219221
const value = data[item.valueKey as keyof GetData];
220222
return `
221223
<g transform="translate(${positions.itemStatsX}, ${15 + idx * 25})">
@@ -285,8 +287,8 @@ export default async function card(data: GetData, uiConfig: UiConfig): Promise<s
285287
<text x="${positions.userX}" y="${positions.userY}" direction="ltr" class="text-username div-animation">@${data.username}</text>
286288
<g class="div-animation text-middle">
287289
<text x="${positions.follX}" y="${positions.follY}" class="text-followers">
288-
<tspan class="text-bold">${data.followers}</tspan> ${selectedLocale.followersText || defaultLocale.followersText} ·
289-
<tspan class="text-bold">${data.following}</tspan> ${selectedLocale.followingText || defaultLocale.followingText}
290+
<tspan class="text-bold">${data.followers}</tspan> ${selectedLocale.followersText} ·
291+
<tspan class="text-bold">${data.following}</tspan> ${selectedLocale.followingText}
290292
</text>
291293
</g>
292294
${cardItemsSVG}

0 commit comments

Comments
 (0)