-
Notifications
You must be signed in to change notification settings - Fork 551
Languages subpackage #292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Languages subpackage #292
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
63e3d56
Boring scaffolding
julien-c ddcad48
Create index.ts
julien-c de2d310
Add a `const LANGUAGES` for good measure
julien-c a2f841b
📦 Add missing pnpm-lock
coyotte508 b250f0d
📝 Add Readme.md
coyotte508 f2308a3
♻️ Split up into multiple files
coyotte508 153fa19
✅ Add tests
coyotte508 36be99f
💡 Add warning
coyotte508 6d83643
🔧 Configure tsup
coyotte508 4c85033
🔧 Also build .d.ts files
coyotte508 43ad912
🙈 Ignore dist files for prettier check
coyotte508 3550752
🚨 Fix type issues
coyotte508 0494756
Update .github/workflows/languages-publish.yml
julien-c 1057dda
✏️ Updte public committer email
coyotte508 49dc263
WDYT?
julien-c a89281a
Update languages_iso_639_3.ts
julien-c 3416782
Revert "WDYT?"
julien-c 280ce8b
typing not really needed no?
julien-c File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| name: Languages - Version and Release | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| newversion: | ||
| description: "Semantic Version Bump Type (major minor patch)" | ||
| default: patch | ||
|
|
||
| defaults: | ||
| run: | ||
| working-directory: packages/languages | ||
|
|
||
| jobs: | ||
| version_and_release: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v3 | ||
| with: | ||
| token: ${{ secrets.BOT_ACCESS_TOKEN }} | ||
| - run: corepack enable | ||
| - uses: actions/setup-node@v3 | ||
| with: | ||
| node-version: "18" | ||
| cache: "pnpm" | ||
| cache-dependency-path: | | ||
| packages/languages/pnpm-lock.yaml | ||
| packages/doc-internal/pnpm-lock.yaml | ||
| # setting a registry enables the NODE_AUTH_TOKEN env variable where we can set an npm token. REQUIRED | ||
| registry-url: "https://registry.npmjs.org" | ||
| - run: pnpm install | ||
| - run: git config --global user.name machineuser | ||
| - run: git config --global user.email infra+machineuser@huggingface.co | ||
| - run: | | ||
| PACKAGE_VERSION=$(node -p "require('./package.json').version") | ||
| BUMPED_VERSION=$(node -p "require('semver').inc('$PACKAGE_VERSION', '${{ github.event.inputs.newversion }}')") | ||
| # Update package.json with the new version | ||
| node -e "const fs = require('fs'); const package = JSON.parse(fs.readFileSync('./package.json')); package.version = '$BUMPED_VERSION'; fs.writeFileSync('./package.json', JSON.stringify(package, null, '\t') + '\n');" | ||
| pnpm --filter doc-internal run fix-cdn-versions | ||
| git add ../.. | ||
| git commit -m "🔖 @hugginface/languages $BUMPED_VERSION" | ||
| git tag "languages-v$BUMPED_VERSION" | ||
| - run: pnpm publish --no-git-checks . | ||
| env: | ||
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
| - run: git push --follow-tags | ||
| # hack - reuse actions/setup-node@v3 just to set a new registry | ||
| - uses: actions/setup-node@v3 | ||
| with: | ||
| node-version: "18" | ||
| registry-url: "https://npm.pkg.github.com" | ||
| - run: pnpm publish --no-git-checks . | ||
| env: | ||
| NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| pnpm-lock.yaml | ||
| # In order to avoid code samples to have tabs, they don't display well on npm | ||
| README.md | ||
| dist |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # 🤗 Hugging Face Languages.js | ||
|
|
||
| The list of all languages supported by the huggingface hub. | ||
|
|
||
| ## Install | ||
|
|
||
| ```console | ||
| pnpm add @huggingface/languages | ||
|
|
||
| npm add @huggingface/languages | ||
|
|
||
| yarn add @huggingface/languages | ||
| ``` | ||
|
|
||
| ### Deno | ||
|
|
||
| ```ts | ||
| // esm.sh | ||
| import { language, wikiLink, type Language } from "https://esm.sh/@huggingface/languages" | ||
| // or npm: | ||
| import { language, wikiLink, type Language } from "npm:@huggingface/languages" | ||
| ``` | ||
|
|
||
| Check out the [full documentation](https://huggingface.co/docs/huggingface.js/languages/README). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| { | ||
| "name": "@huggingface/languages", | ||
| "packageManager": "pnpm@8.3.1", | ||
| "version": "0.1.0", | ||
| "description": "List of ISO-639 languages used in the Hub", | ||
| "repository": "https://github.com/huggingface/huggingface.js.git", | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "main": "./dist/index.js", | ||
| "module": "./dist/index.mjs", | ||
| "types": "./dist/index.d.ts", | ||
| "exports": { | ||
| ".": { | ||
| "types": "./dist/index.d.ts", | ||
| "require": "./dist/index.js", | ||
| "import": "./dist/index.mjs" | ||
| } | ||
| }, | ||
| "source": "index.ts", | ||
| "scripts": { | ||
| "lint": "eslint --quiet --fix --ext .cjs,.ts .", | ||
| "lint:check": "eslint --ext .cjs,.ts .", | ||
| "format": "prettier --write .", | ||
| "format:check": "prettier --check .", | ||
| "prepublishOnly": "pnpm run build", | ||
| "build": "tsup src/index.ts --format cjs,esm --clean --dts", | ||
| "test": "vitest run", | ||
| "type-check": "tsc" | ||
| }, | ||
| "files": [ | ||
| "dist", | ||
| "index.ts", | ||
| "tsconfig.json" | ||
| ], | ||
| "keywords": [ | ||
| "huggingface", | ||
| "hub", | ||
| "languages" | ||
| ], | ||
| "author": "Hugging Face", | ||
| "license": "MIT", | ||
| "devDependencies": { | ||
| "typescript": "^5.0.4" | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| export type { Language } from "./types"; | ||
| export { language } from "./language"; | ||
| export { wikiLink } from "./wikiLink"; | ||
| export { LANGUAGES_ISO_639_1 } from "./languages_iso_639_1"; | ||
| export { LANGUAGES_ISO_639_3 } from "./languages_iso_639_3"; | ||
julien-c marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { language } from "./language"; | ||
|
|
||
| describe("language", () => { | ||
| it("should return an object for a 2-letter language code", () => { | ||
| expect(language("en")).toMatchObject({ | ||
| code: "en", | ||
| name: "English", | ||
| nativeName: "English", | ||
| }); | ||
| }); | ||
|
|
||
| it("should return an object for a 3-letter language code", () => { | ||
| expect(language("eng")).toMatchObject({ | ||
| code: "eng", | ||
| name: "English", | ||
| }); | ||
|
|
||
| expect(language("fra")).toMatchObject({ | ||
| code: "fra", | ||
| name: "French", | ||
| }); | ||
| }); | ||
|
|
||
| it("should return null for an invalid language code", () => { | ||
| expect(language("invalid")).toBeNull(); | ||
| }); | ||
| }); |
julien-c marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import { LANGUAGES_ISO_639_1 } from "./languages_iso_639_1"; | ||
| import { LANGUAGES_ISO_639_3 } from "./languages_iso_639_3"; | ||
| import type { Language } from "./types"; | ||
|
|
||
| /** | ||
| * Be careful importing this function in frontend code, as it will import all languages. | ||
| */ | ||
| export function language(code: string): Language | null { | ||
| if (code in LANGUAGES_ISO_639_1) { | ||
| return LANGUAGES_ISO_639_1[code as keyof typeof LANGUAGES_ISO_639_1]; | ||
| } | ||
| if (code in LANGUAGES_ISO_639_3) { | ||
| return LANGUAGES_ISO_639_3[code as keyof typeof LANGUAGES_ISO_639_3]; | ||
| } | ||
|
|
||
| return null; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.