Skip to content

Commit

Permalink
fix: support any custom component (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
sahinvardar authored Nov 3, 2023
1 parent a0b9718 commit a30a096
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vardario/svelte-i18next",
"version": "0.1.17",
"version": "0.1.18",
"description": "",
"license": "MIT",
"author": "Sahin Vardar",
Expand Down
4 changes: 2 additions & 2 deletions src/extract-i18n-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as compiler from 'svelte/compiler';
import { Ast } from 'svelte/types/compiler/interfaces.js';
import { PreprocessorGroup } from 'svelte/types/compiler/preprocess';
import { extractKeyPathFromFile, stripScriptTag } from './string-utils.js';
import { SUPPORTED_COMPONENTS, scanDir } from './utils.js';
import { scanDir } from './utils.js';

function extractI18nKeys(ast: Ast | Node, callIdentifier: string): string[] {
const result: string[] = [];
Expand All @@ -27,7 +27,7 @@ function extractI18nKeys(ast: Ast | Node, callIdentifier: string): string[] {
}
}

if (node.type === 'InlineComponent' && SUPPORTED_COMPONENTS.includes(node.name)) {
if (node.type === 'InlineComponent') {
const nameAttribute = node.attributes?.find((attr: any) => attr.name === 'name');
if (nameAttribute) {
result.push(nameAttribute.value[0].data);
Expand Down
3 changes: 1 addition & 2 deletions src/i18n-preprocessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import * as compiler from 'svelte/compiler';
import { Ast, TemplateNode } from 'svelte/types/compiler/interfaces';
import type { PreprocessorGroup } from 'svelte/types/compiler/preprocess';
import { extractKeyPathFromFile, stripScriptTag } from './string-utils.js';
import { SUPPORTED_COMPONENTS } from './utils.js';

export function create18nCallLabelAttribute(callIdentifier: string, i18nKey: string) {
const expression = parse(`${callIdentifier}("${i18nKey}")`, { ecmaVersion: 'latest' });
Expand Down Expand Up @@ -52,7 +51,7 @@ export function adjustI18nCall(ast: Ast | Node, prefix: string, callIdentifier:
export function adjustInputElementLabels(ast: Ast, prefix: string, callIdentifier: string = '$i18n') {
compiler.walk(ast.html, {
enter: (node: TemplateNode) => {
if (node.type === 'InlineComponent' && SUPPORTED_COMPONENTS.includes(node.name)) {
if (node.type === 'InlineComponent') {
const nameAttribute = node.attributes?.find((attr: any) => attr.name === 'name');
const labelAttribute = node.attributes?.find((attr: any) => attr.name === 'label');

Expand Down
2 changes: 0 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,3 @@ export function __dirname(meta: ImportMeta) {
const __filename = url.fileURLToPath(import.meta.url);
return path.dirname(__filename);
}

export const SUPPORTED_COMPONENTS = ['Input', 'Checkbox', 'Select', 'BubbleSelect', 'LocalizedInput'];

0 comments on commit a30a096

Please sign in to comment.