Skip to content

Commit

Permalink
feat: add plugin-i18next (#29)
Browse files Browse the repository at this point in the history
Co-authored-by: Jeroen Claassens <jeroen.claassens@live.nl>
Co-authored-by: Antonio Román <kyradiscord@gmail.com>
Co-authored-by: Jeroen Claassens <support@favware.tech>
Co-authored-by: Nytelife26 <xtylerjrx@gmail.com>
  • Loading branch information
5 people committed Jan 1, 2021
1 parent cf55282 commit 41e6581
Show file tree
Hide file tree
Showing 23 changed files with 804 additions and 51 deletions.
3 changes: 2 additions & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
@@ -1 +1,2 @@
/packages/api @favna @QuantumlyTangled
/packages/api @favna @kyranet
/packages/i18next @nytelife26 @favna @kyranet
71 changes: 71 additions & 0 deletions .github/workflows/cd-i18next.yml
@@ -0,0 +1,71 @@
name: Continuous Delivery - i18next

on:
push:
branches:
- main
paths:
- packages/i18next/**
- .all-contributorsrc
- LICENSE.md
- package.json
- .github/workflows/cd-i18next.yml

jobs:
BuildI18next:
name: Publish i18next
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[skip ci]')"
steps:
- name: Checkout Project
uses: actions/checkout@v2
- name: Use Node.js 14
uses: actions/setup-node@v1
with:
node-version: 14
- name: Restore CI Cache
uses: actions/cache@v1
with:
path: node_modules
key: ${{ runner.os }}-14-${{ hashFiles('**/yarn.lock') }}
- name: Install Dependencies
run: yarn --ignore-scripts --frozen-lockfile
- name: Build Code
run: yarn workspace @sapphire/plugin-i18next build
- name: Push new code
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
run: |
echo -e "\n# Initialize some useful variables"
REPO="https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
BRANCH_OR_TAG=`awk -F/ '{print $2}' <<< $GITHUB_REF`
CURRENT_BRANCH=`awk -F/ '{print $NF}' <<< $GITHUB_REF`
if [ "$BRANCH_OR_TAG" == "heads" ]; then
SOURCE_TYPE="branch"
else
SOURCE_TYPE="tag"
fi
echo -e "\n# Move to the i18next directory"
cd packages/i18next
echo -e "\n# Checkout the repo in the target branch"
TARGET_BRANCH="build-i18next"
git clone $REPO out -b $TARGET_BRANCH
echo -e "\n# Remove any old files in the dist folder"
rm -rfv out/dist/*
echo -e "\n# Move the generated code to the newly-checked-out repo, to be committed and pushed"
rsync -vaI package.json out/
rsync -vaI ../../.all-contributorsrc out/
rsync -vaI ../../LICENSE.md out/
rsync -vaI README.md out/
rsync -vaI dist/ out/dist
rsync -vaI register* out/
echo -e "\n# Commit and push"
cd out
git add --all .
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_EMAIL}"
git commit -m "build: i18next build for ${GITHUB_SHA}" || true
git push origin $TARGET_BRANCH
env:
GITHUB_TOKEN: ${{ secrets.SKYRA_TOKEN }}
GITHUB_ACTOR: NM-EEA-Y
GITHUB_EMAIL: contact@skyra.pw
85 changes: 85 additions & 0 deletions packages/i18next/README.md
@@ -0,0 +1,85 @@
<div align="center">

![Sapphire Logo](https://cdn.skyra.pw/gh-assets/sapphire.png)

# @sapphire/plugin-i18next

**Plugin for <a href="https://github.com/sapphire-project/framework">@sapphire/framework</a> to support i18next based internationalization.**

[![GitHub](https://img.shields.io/github/license/sapphire-project/plugins)](https://github.com/sapphire-project/plugins/blob/main/LICENSE.md)
[![Total alerts](https://img.shields.io/lgtm/alerts/g/sapphire-project/plugins.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/sapphire-project/plugins/alerts/)
[![Language grade: JavaScript](https://img.shields.io/lgtm/grade/javascript/g/sapphire-project/plugins.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/sapphire-project/plugins/context:javascript)
[![Coverage Status](https://coveralls.io/repos/github/sapphire-project/plugins/badge.svg?branch=main)](https://coveralls.io/github/sapphire-project/plugins?branch=main)
[![npm bundle size](https://img.shields.io/bundlephobia/min/@sapphire/plugin-in17n?logo=webpack&style=flat-square)](https://bundlephobia.com/result?p=@sapphire/plugin-in17n)
[![npm](https://img.shields.io/npm/v/@sapphire/plugin-in17n?color=crimson&logo=npm&style=flat-square)](https://www.npmjs.com/package/@sapphire/plugin-in17n)
[![Depfu](https://badges.depfu.com/badges/11bbf7392987e6fd51fc6559e1d42dfc/count.svg)](https://depfu.com/github/sapphire-project/plugins?project_id=15201)

</div>

## Description

An implementation of i18next's [filesystem backend] for Sapphire. It allows you to use a JSON-based `languages` directory to add internationalization for your bot using `SapphireClient`'s `fetchLanguage` hook and a custom message extension, adding features such as `sendTranslated` and `fetchLanguageKey`.

[filesystem backend]: https://github.com/i18next/i18next-fs-backend

## Features

- Fully ready for TypeScript!
- Includes ESM ready entrypoint
- Framework agnostic
- Includes convenience register for discord.js

## Installation

```sh
yarn add -D @sapphire/plugin-i18next
```

---

## Usage

```typescript
import '@sapphire/plugin-i18next/register';
```

And for discord.js:

```typescript
import '@sapphire/plugin-i18next/register-discordjs';
```

It is to be noted that unless you are using discord.js, which has the convenience register to extend the client and message methods for you, you will have to implement your own extensions.

This is currently undocumented and not covered by guides, but will be in the future. For now, you may follow the structure of `register-discordjs.ts` if this is the case for you.

## Sapphire i18next Documentation

For the full @sapphire/plugin-i18next documentation please refer to the TypeDoc generated [documentation](https://sapphire-project.github.io/plugins/modules/_sapphire_plugin_i18next.html).

## Buy us some doughnuts

Sapphire Project is and always will be open source, even if we don't get donations. That being said, we know there are amazing people who may still want to donate just to show their appreciation. Thank you very much in advance!

We accept donations through Open Collective, Ko-fi, Paypal, Patreon and GitHub Sponsorships. You can use the buttons below to donate through your method of choice.

| Donate With | Address |
| :-------------: | :----------------------------------------------------------------------------------------------: |
| Open Collective | [Click Here](https://opencollective.com/sapphire-project) |
| Ko-fi | [Click Here](https://ko-fi.com/sapphireproject) |
| Patreon | [Click Here](https://www.patreon.com/sapphire_project) |
| PayPal | [Click Here](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=SP738BQTQQYZY) |

## Contributors ✨

Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<!-- markdownlint-restore -->
<!-- prettier-ignore-end -->

<!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
15 changes: 15 additions & 0 deletions packages/i18next/jest.config.ts
@@ -0,0 +1,15 @@
import type { Config } from '@jest/types';

// eslint-disable-next-line @typescript-eslint/require-await
export default async (): Promise<Config.InitialOptions> => ({
displayName: 'unit test',
preset: 'ts-jest',
testEnvironment: 'node',
testRunner: 'jest-circus/runner',
testMatch: ['<rootDir>/tests/**/*.test.ts'],
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tests/tsconfig.json'
}
}
});
90 changes: 90 additions & 0 deletions packages/i18next/package.json
@@ -0,0 +1,90 @@
{
"name": "@sapphire/plugin-i18next",
"version": "0.0.1",
"description": "Plugin for @sapphire/framework to support i18next.",
"author": "@sapphire",
"license": "MIT",
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"exports": {
".": {
"import": "./dist/index.mjs",
"require": "./dist/index.js"
},
"./register": {
"import": "./register.mjs",
"require": "./register.js"
},
"./register-discordjs": {
"import": "./register-discordjs.mjs",
"require": "./register-discordjs.js"
}
},
"homepage": "https://github.com/sapphire-project/plugins/tree/main/packages/i18next",
"scripts": {
"test": "jest",
"lint": "eslint src tests --ext ts --fix",
"build": "tsc -b src",
"postbuild": "run-p esm:**",
"esm:register": "gen-esm-wrapper dist/register.js dist/register.mjs",
"esm:register-discordjs": "gen-esm-wrapper dist/register-discordjs.js dist/register-discordjs.mjs",
"esm:default": "gen-esm-wrapper dist/index.js dist/index.mjs",
"prepublishOnly": "yarn build"
},
"dependencies": {
"@sapphire/utilities": "^1.3.0",
"i18next": "^19.8.4",
"i18next-fs-backend": "^1.0.7"
},
"peerDependencies": {
"@sapphire/framework": "1.x",
"@sapphire/pieces": "1.x",
"@types/i18next-fs-backend": "^1.0.0",
"discord.js": "^12.x"
},
"peerDependenciesMeta": {
"@types/i18next-fs-backend": {
"optional": true
},
"discord.js": {
"optional": true
}
},
"devDependencies": {
"@types/i18next-fs-backend": "^1.0.0"
},
"repository": {
"type": "git",
"url": "git+https://github.com/sapphire-project/plugins.git",
"directory": "packages/i18next"
},
"files": [
"dist",
"!dist/*.tsbuildinfo",
"register.*",
"register-discordjs.*"
],
"engines": {
"node": ">=14",
"npm": ">=6"
},
"keywords": [
"sapphire-project",
"plugin",
"bot",
"typescript",
"ts",
"yarn",
"discord",
"sapphire",
"i18next",
"i18n"
],
"bugs": {
"url": "https://github.com/sapphire-project/plugins/issues"
},
"publishConfig": {
"access": "public"
}
}
1 change: 1 addition & 0 deletions packages/i18next/register-discordjs.d.ts
@@ -0,0 +1 @@
export * from './dist/register-discordjs';
4 changes: 4 additions & 0 deletions packages/i18next/register-discordjs.js
@@ -0,0 +1,4 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const tslib = require('tslib');

tslib.__exportStar(require('./dist/register-discordjs.js'), exports);
1 change: 1 addition & 0 deletions packages/i18next/register-discordjs.mjs
@@ -0,0 +1 @@
export * from './dist/register-discordjs.mjs';
1 change: 1 addition & 0 deletions packages/i18next/register.d.ts
@@ -0,0 +1 @@
export * from './dist/register';
4 changes: 4 additions & 0 deletions packages/i18next/register.js
@@ -0,0 +1,4 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const tslib = require('tslib');

tslib.__exportStar(require('./dist/register.js'), exports);
1 change: 1 addition & 0 deletions packages/i18next/register.mjs
@@ -0,0 +1 @@
export * from './dist/register.mjs';
2 changes: 2 additions & 0 deletions packages/i18next/src/index.ts
@@ -0,0 +1,2 @@
export * from './lib/types/options';
export * from './lib/I18nextHandler';

0 comments on commit 41e6581

Please sign in to comment.