Skip to content

Commit 200d13e

Browse files
authored
chore(i18n): Extract strings into messages file (#37)
1 parent be0605f commit 200d13e

15 files changed

+128
-45
lines changed

bun.lockb

478 Bytes
Binary file not shown.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
2-
"name": "GitHub: Better Line Counts",
3-
"description": "Remove generated files from GitHub line counts",
2+
"name": "github-better-line-counts",
43
"private": true,
54
"version": "1.7.0",
65
"packageManager": "bun@1.1.31",
@@ -37,6 +36,7 @@
3736
"@types/chrome": "^0.0.269",
3837
"@types/jsdom": "^21.1.3",
3938
"@vitest/coverage-v8": "^2.1.3",
39+
"@wxt-dev/i18n": "^0.2.1",
4040
"@wxt-dev/module-vue": "^1.0.0",
4141
"autoprefixer": "^10.4.16",
4242
"env-cmd": "^10.1.0",

src/components/CommitDiff.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export const CommitDiff = createDiffComponent({
77
const container = this.getDeletionsElement()?.parentElement;
88
container?.appendChild(spinner);
99
},
10-
getAdditionsText: (count) => `${count} additions`,
11-
getDeletionsText: (count) => `${count} deletions`,
12-
getGeneratedText: (count) => `${count} generated lines.`,
10+
getAdditionsText: (count) => i18n.t("diffs.additionsText", count),
11+
getDeletionsText: (count) => i18n.t("diffs.deletionsText", count),
12+
getGeneratedText: (count) => i18n.t("diffs.generatedText", count),
1313
});

src/components/CompareDiff.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export const CompareDiff = createDiffComponent({
77
const container = this.getDeletionsElement()?.parentElement;
88
container?.appendChild(spinner);
99
},
10-
getAdditionsText: (count) => `${count} additions`,
11-
getDeletionsText: (count) => `${count} deletions`,
12-
getGeneratedText: (count) => `${count} generated lines.`,
10+
getAdditionsText: (count) => i18n.t("diffs.additionsText", count),
11+
getDeletionsText: (count) => i18n.t("diffs.deletionsText", count),
12+
getGeneratedText: (count) => i18n.t("diffs.generatedText", count),
1313
});

src/components/CustomListItem.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script lang="ts" setup>
2-
const props = defineProps<{
2+
defineProps<{
33
value: string;
44
}>();
55
@@ -14,7 +14,7 @@ const emits = defineEmits<{
1414

1515
<textarea
1616
class="font-mono p-2 w-full resize-y m-0 outline-none -mb-1 min-h-[5rem]"
17-
:placeholder="'Enter glob patterns:\n*.lock\n**/vendor/**'"
17+
:placeholder="i18n.t('options.customLists.customRepoPlaceholder')"
1818
:value="value"
1919
@input="
2020
emits('update:value', ($event.target as HTMLTextAreaElement).value)

src/components/CustomListsPref.vue

+11-5
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,32 @@ const all = computed({
2323
};
2424
},
2525
});
26+
27+
const { t } = i18n;
2628
</script>
2729

2830
<template>
2931
<li class="flex flex-col gap-4">
3032
<!-- Header -->
3133
<div class="flex flex-col gap-2">
32-
<p class="font-medium text-base-content text-lg">Custom Lists</p>
34+
<p class="font-medium text-base-content text-lg">
35+
{{ t("options.customLists.title") }}
36+
</p>
3337
<p class="text-base">
34-
Use
38+
{{ t("options.customLists.description1") }}
3539
<a
3640
class="link link-secondary"
3741
href="https://github.com/isaacs/minimatch#features"
3842
target="_blank"
39-
>minimatch</a
43+
>{{ t("options.customLists.description2") }}</a
4044
>
41-
glob patterns to mark files as generated accross all repos.
45+
{{ t("options.customLists.description3") }}
4246
</p>
4347
</div>
4448

4549
<!-- All Repos -->
46-
<CustomListItem v-model:value="all">All Repos</CustomListItem>
50+
<CustomListItem v-model:value="all">{{
51+
i18n.t("options.customLists.allRepos")
52+
}}</CustomListItem>
4753
</li>
4854
</template>

src/components/OptionsForm.vue

+4-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ const { state, hasChanges, reset, saveChanges } = useForm<{
3131
await commitHashDiffsCache.clear();
3232
},
3333
);
34+
35+
const { t } = i18n;
3436
</script>
3537

3638
<template>
@@ -50,10 +52,10 @@ const { state, hasChanges, reset, saveChanges } = useForm<{
5052
:disabled="!hasChanges"
5153
@click="saveChanges"
5254
>
53-
Save Changes
55+
{{ t("saveChanges") }}
5456
</button>
5557
<button class="btn" :disabled="!hasChanges" @click="reset">
56-
Discard
58+
{{ t("discard") }}
5759
</button>
5860
</div>
5961
</form>

src/components/PrDiff.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export const PrDiff = createDiffComponent({
77
const deletions = this.getDeletionsElement();
88
deletions?.replaceWith(deletions, spinner);
99
},
10-
getAdditionsText: (count) => `+${count}`,
11-
getDeletionsText: (count) => `−${count}`,
12-
getGeneratedText: (count) => ` ⌁${count}`,
10+
getAdditionsText: (count) => i18n.t("diffs.additionsSymbol", [count]),
11+
getDeletionsText: (count) => i18n.t("diffs.deletionsSymbol", [count]),
12+
getGeneratedText: (count) => i18n.t("diffs.generatedSymbol", [count]),
1313
});

src/components/ShowGeneratedCountPref.vue

+16-9
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ const hideLineCount = useVModel(props, "hideGeneratedLineCount", emits);
1212
function toggle() {
1313
hideLineCount.value = !hideLineCount.value;
1414
}
15+
16+
const { t } = i18n;
1517
</script>
1618

1719
<template>
1820
<li class="flex flex-col gap-4">
1921
<div class="flex flex-col gap-2">
2022
<p class="font-medium text-base-content text-lg">
21-
Show Generated Line Counts
23+
{{ t("options.enabled.title") }}
2224
</p>
2325
<label class="text-base flex gap-4 items-center">
2426
<input
@@ -28,14 +30,19 @@ function toggle() {
2830
@change="toggle"
2931
/>
3032
<p>
31-
Along with
32-
<span class="text-success font-medium">+additions</span> and
33-
<span class="text-error font-medium">−deletions</span>, show a third
34-
number for
35-
<span class="text-base-content text-opacity-50 font-medium"
36-
>⌁generated</span
37-
>
38-
lines.
33+
{{ t("options.enabled.description1") }}
34+
<span class="text-success font-medium">{{
35+
t("options.enabled.description2")
36+
}}</span>
37+
{{ t("options.enabled.description3") }}
38+
<span class="text-error font-medium">{{
39+
t("options.enabled.description4")
40+
}}</span
41+
>{{ t("options.enabled.description5") }}
42+
<span class="text-base-content text-opacity-50 font-medium">{{
43+
t("options.enabled.description6")
44+
}}</span>
45+
{{ t("options.enabled.description7") }}
3946
</p>
4047
</label>
4148
</div>

src/components/TokenPref.vue

+21-11
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,32 @@ const token = useVModel(props, "githubPat", emits);
1515
const { data: user, error, isLoading } = useGithubUserQuery(token);
1616
1717
const tokenHidden = ref(true);
18+
19+
const { t } = i18n;
1820
</script>
1921

2022
<template>
2123
<li class="flex flex-col gap-4">
2224
<div class="flex flex-col gap-2">
23-
<p class="font-medium text-base-content text-lg">Access Private Repos</p>
25+
<p class="font-medium text-base-content text-lg">
26+
{{ t("options.privateRepos.title") }}
27+
</p>
2428
<p class="text-base">
25-
<em>Optional:</em> To recalculate the diff on private repos, the
26-
extension needs a GitHub PAT to authenticate API requests.
29+
<em>{{ t("options.privateRepos.description1") }}</em>
30+
{{ t("options.privateRepos.description2") }}
2731
<a
2832
class="link link-secondary"
2933
href="https://github.com/settings/tokens/new?description=Github%3A%20Better%20Line%20Count&scopes=repo"
3034
target="_blank"
31-
>Click here</a
35+
>{{ t("options.privateRepos.description3") }}</a
3236
>
33-
to create one.
37+
{{ t("options.privateRepos.description4") }}
3438
</p>
3539
</div>
3640
<div class="join">
3741
<input
3842
class="join-item input input-bordered w-full"
39-
placeholder="Personal access token..."
43+
:placeholder="t('options.privateRepos.inputPlaceholder')"
4044
v-model="token"
4145
:type="tokenHidden ? 'password' : 'text'"
4246
/>
@@ -53,17 +57,23 @@ const tokenHidden = ref(true);
5357

5458
<template v-if="token">
5559
<p v-if="error" class="">
56-
<span class="badge badge-error shrink-0">Token is invalid</span>
60+
<span class="badge badge-error shrink-0">{{
61+
t("options.privateRepos.invalidToken")
62+
}}</span>
5763
{{ " " }}
5864
<span class="text-sm">{{ error }}</span>
5965
</p>
6066
<p v-else-if="isLoading || user == null" class="badge badge-ghost">
61-
Checking token...
67+
{{ t("options.privateRepos.checking") }}
6268
</p>
63-
<p v-else class="">
64-
<span class="badge badge-success">Token is valid</span>
69+
<p v-else>
70+
<span class="badge badge-success">{{
71+
t("options.privateRepos.validToken")
72+
}}</span>
6573
{{ " " }}
66-
<span class="text-sm">Username: {{ user?.login }}</span>
74+
<span class="text-sm">{{
75+
t("options.privateRepos.username", [user.login])
76+
}}</span>
6777
</p>
6878
</template>
6979
</li>

src/components/createDiffComponent.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,15 @@ export function createDiffComponent(options: {
4444
if (!hideGeneratedLineCount) {
4545
const generated = document.createElement("strong");
4646
generated.id = DIFF_COMPONENT_ID;
47-
generated.textContent = options.getGeneratedText(stats.exclude.changes);
47+
generated.textContent =
48+
" " + options.getGeneratedText(stats.exclude.changes);
4849
generated.style.color = GREY_COLOR;
49-
const generatedAdditionsText = `+${stats.exclude.additions}`;
50-
const generatedDeletionsText = `−${stats.exclude.deletions}`;
50+
const generatedAdditionsText = i18n.t("diffs.additionsSymbol", [
51+
stats.exclude.additions,
52+
]);
53+
const generatedDeletionsText = i18n.t("diffs.deletionsSymbol", [
54+
stats.exclude.deletions,
55+
]);
5156
generated.title = `${generatedAdditionsText} ${generatedDeletionsText}`;
5257
spinner.replaceWith(generated);
5358
} else {

src/entrypoints/options/index.html

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
<meta charset="UTF-8" />
55
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7-
<title>Options</title>
87
<script src="./main.ts" type="module"></script>
98
<link rel="stylesheet" href="~/assets/tailwind.css" />
109
<meta name="manifest.open_in_tab" content="false" />

src/entrypoints/options/main.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import Options from "@/pages/Options.vue";
22
import { VueQueryPlugin } from "@tanstack/vue-query";
33

4+
document.title = i18n.t("options.title");
5+
46
createApp(Options).use(VueQueryPlugin).mount(document.body);

src/locales/en.yml

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: GitHub Better Line Counts
2+
description: Remove generated files from GitHub line counts
3+
saveChanges: Save Changes
4+
discard: Discard
5+
diffs:
6+
additionsText:
7+
1: $1 addition
8+
n: $1 additions
9+
deletionsText:
10+
1: $1 deletion
11+
n: $1 deletions
12+
generatedText:
13+
1: $1 generated line.
14+
n: $1 generated lines.
15+
additionsSymbol: +$1
16+
deletionsSymbol: −$1
17+
generatedSymbol: ⌁$1
18+
options:
19+
title: Options
20+
privateRepos:
21+
title: Access Private Repos
22+
description1: "Optional:"
23+
description2: To recalculate the diff on private repos, the extension needs a GitHub PAT to authenticate API requests.
24+
description3: Click here
25+
description4: to create one.
26+
inputPlaceholder: Personal access token...
27+
invalidToken: Token is invalid
28+
validToken: Token is valid
29+
checking: Checking token...
30+
username: "Username: $1"
31+
enabled:
32+
title: Show Generated Line Counts
33+
description1: Along with
34+
description2: +additions
35+
description3: and
36+
description4: −deletions
37+
description5: ", show a third number for"
38+
description6: ⌁generated
39+
description7: lines.
40+
customLists:
41+
title: Custom Lists
42+
description1: Use
43+
description2: minimatch
44+
description3: glob patterns to mark files as generated across all repos.
45+
allRepos: All Repos
46+
customRepoPlaceholder: |
47+
Enter glob patterns:
48+
*.lock
49+
**/vendor/**

wxt.config.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default defineConfig({
99
experimental: {
1010
entrypointImporter: "vite-node",
1111
},
12-
modules: ["@wxt-dev/module-vue"],
12+
modules: ["@wxt-dev/module-vue", "@wxt-dev/i18n/module"],
1313
imports: {
1414
presets: ["vue-router", "@vueuse/core"],
1515
imports: [
@@ -30,6 +30,9 @@ export default defineConfig({
3030
permissions.push("https://api.github.com/*");
3131
}
3232
return {
33+
default_locale: "en",
34+
name: "__MSG_name__",
35+
description: "__MSG_description__",
3336
permissions,
3437
};
3538
},

0 commit comments

Comments
 (0)