Skip to content

Commit

Permalink
chore: Release v0.0.1-alpha.12 (#439)
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod authored Sep 16, 2024
2 parents 3050ad0 + 50b18ae commit f31b092
Show file tree
Hide file tree
Showing 179 changed files with 10,108 additions and 7,256 deletions.
54 changes: 54 additions & 0 deletions .github/ISSUE_TEMPLATE/i18n.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: 🌐 Internationalization (i18n)
description: Contribute to or report issues with translations
title: "[i18n]: "
labels: ["i18n", "triage"]
body:
- type: markdown
attributes:
value: |
Thanks for taking the time to contribute to our internationalization efforts!
Before proceeding, please check our [i18n Contribution Guidelines](https://github.com/RSSNext/Follow/blob/dev/wiki/contribute-i18n.md) for detailed instructions.
- type: dropdown
id: type
attributes:
label: Type of i18n contribution
options:
- New language support
- Update existing translations
- Report incorrect translation
- Other i18n-related issue
validations:
required: true
- type: input
id: language
attributes:
label: Language
description: What language are you contributing to or reporting about?
placeholder: e.g., Spanish, French, Japanese
validations:
required: true
- type: textarea
id: description
attributes:
label: Description
description: Please provide details about your contribution or the issue you're reporting.
placeholder: |
For new languages: List any specific challenges or considerations.
For updates: Describe what you're changing and why.
For issues: Provide the incorrect translation and suggest a correction.
validations:
required: true
- type: textarea
id: additional-context
attributes:
label: Additional context
description: Add any other context, screenshots, or file references here.
- type: checkboxes
id: terms
attributes:
label: Code of Conduct
description: By submitting this issue, you agree to follow our [Code of Conduct](https://example.com/code-of-conduct)
options:
- label: I agree to follow this project's Code of Conduct
required: true
12 changes: 3 additions & 9 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,7 @@
"typescript.tsdk": "node_modules/typescript/lib",
"i18n-ally.enabledFrameworks": ["i18next"],
"i18n-ally.displayLanguage": "en",
"i18n-ally.localesPaths": [
// "locales/app",
// "locales/lang",
// "locales/common",
"locales/**/*"
]
// "i18n-ally.namespace": true,
// "i18n-ally.pathMatcher": "{namespace}/{locale}.json",
// "i18n-ally.defaultNamespace": "app",
"i18n-ally.localesPaths": ["locales"],
"i18n-ally.namespace": true,
"i18n-ally.pathMatcher": "{namespaces}/{locale}.json"
}
60 changes: 59 additions & 1 deletion CHANGELOG.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ You can get an invitation code in the following ways:

If you have access, you are welcome to use the following methods to download and install it:

- Visit our online webapp at [app.follow.is](https://app.follow.is)
- You can get the installation packages for each platform from the [Releases page](https://github.com/RSSNext/Follow/releases).
- If you are using Arch linux, you can install package [follow-appimage](https://aur.archlinux.org/packages/follow-appimage) that maintained by [timochan](https://github.com/ttimochan).

Expand Down
60 changes: 60 additions & 0 deletions configs/i18n-completeness.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import fs from "node:fs"
import path from "node:path"

type LanguageCompletion = Record<string, number>

function getLanguageFiles(dir: string): string[] {
return fs.readdirSync(dir).filter((file) => file.endsWith(".json"))
}

function getNamespaces(localesDir: string): string[] {
return fs
.readdirSync(localesDir)
.filter((file) => fs.statSync(path.join(localesDir, file)).isDirectory())
}

function countKeys(obj: any): number {
let count = 0
for (const key in obj) {
if (typeof obj[key] === "object") {
count += countKeys(obj[key])
} else {
count++
}
}
return count
}

function calculateCompleteness(localesDir: string): LanguageCompletion {
const namespaces = getNamespaces(localesDir)
const languages = new Set<string>()
const keyCount: Record<string, number> = {}

namespaces.forEach((namespace) => {
const namespaceDir = path.join(localesDir, namespace)
const files = getLanguageFiles(namespaceDir)

files.forEach((file) => {
const lang = path.basename(file, ".json")
languages.add(lang)

const content = JSON.parse(fs.readFileSync(path.join(namespaceDir, file), "utf-8"))
keyCount[lang] = (keyCount[lang] || 0) + countKeys(content)
})
})

const enCount = keyCount["en"] || 0
const completeness: LanguageCompletion = {}

languages.forEach((lang) => {
if (lang !== "en") {
const percent = Math.round((keyCount[lang] / enCount) * 100)
completeness[lang] = percent
}
})

return completeness
}

const i18n = calculateCompleteness(path.resolve(__dirname, "../locales"))
export default i18n
94 changes: 73 additions & 21 deletions configs/vite.render.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { readFileSync } from "node:fs"
import { resolve } from "node:path"
import fs, { readFileSync } from "node:fs"
import path, { resolve } from "node:path"

import * as babel from "@babel/core"
import generate from "@babel/generator"
Expand All @@ -11,9 +11,76 @@ import { prerelease } from "semver"
import type { Plugin, UserConfig } from "vite"

import { getGitHash } from "../scripts/lib"
import i18nCompleteness from "./i18n-completeness"

const pkg = JSON.parse(readFileSync("package.json", "utf8"))
const isCI = process.env.CI === "true" || process.env.CI === "1"
function localesPlugin(): Plugin {
return {
name: "locales-merge",
enforce: "post",
generateBundle(options, bundle) {
const localesDir = path.resolve(__dirname, "../locales")
const namespaces = fs.readdirSync(localesDir)
const languageResources = {}

namespaces.forEach((namespace) => {
const namespacePath = path.join(localesDir, namespace)
const files = fs.readdirSync(namespacePath).filter((file) => file.endsWith(".json"))

files.forEach((file) => {
const lang = path.basename(file, ".json")
const filePath = path.join(namespacePath, file)
const content = JSON.parse(fs.readFileSync(filePath, "utf-8"))

if (!languageResources[lang]) {
languageResources[lang] = {}
}
languageResources[lang][namespace] = content
})
})

Object.entries(languageResources).forEach(([lang, resources]) => {
const fileName = `locales/${lang}.js`
const content = `export default ${JSON.stringify(resources)};`

this.emitFile({
type: "asset",
fileName,
source: content,
})
})

// Remove original JSON chunks
Object.keys(bundle).forEach((key) => {
if (key.startsWith("locales/") && key.endsWith(".json")) {
delete bundle[key]
}
})
},
}
}

function customI18nHmrPlugin(): Plugin {
return {
name: "custom-i18n-hmr",
handleHotUpdate({ file, server }) {
if (file.endsWith(".json") && file.includes("locales")) {
server.ws.send({
type: "custom",
event: "i18n-update",
data: {
file,
content: readFileSync(file, "utf-8"),
},
})

// return empty array to prevent the default HMR
return []
}
},
}
}

export const viteRenderBaseConfig = {
resolve: {
Expand Down Expand Up @@ -52,26 +119,9 @@ export const viteRenderBaseConfig = {
},
}),

localesPlugin(),
viteTwToRawString(),

{
name: "custom-i18n-hmr",
handleHotUpdate({ file, server }) {
if (file.endsWith(".json") && file.includes("locales")) {
server.ws.send({
type: "custom",
event: "i18n-update",
data: {
file,
content: readFileSync(file, "utf-8"),
},
})

// return empty array to prevent the default HMR
return []
}
},
},
customI18nHmrPlugin(),
],
define: {
APP_VERSION: JSON.stringify(pkg.version),
Expand All @@ -83,6 +133,8 @@ export const viteRenderBaseConfig = {
RELEASE_CHANNEL: JSON.stringify((prerelease(pkg.version)?.[0] as string) || "stable"),

DEBUG: process.env.DEBUG === "true",

I18N_COMPLETENESS_MAP: JSON.stringify({ ...i18nCompleteness, en: 100 }),
},
} satisfies UserConfig

Expand Down
18 changes: 18 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,22 @@ export default defineConfig(
],
},
},
{
files: ["**/*.tsx"],
rules: {
"@stylistic/jsx-self-closing-comp": "error",
},
},
{
files: ["locales/**/*.json"],
rules: {
"jsonc/sort-keys": [
"error",
{
pathPattern: ".*",
order: { type: "asc" },
},
],
},
},
)
1 change: 1 addition & 0 deletions icons/mgc/photo_album_cute_fi.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions icons/mgc/photo_album_cute_re.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit f31b092

Please sign in to comment.