Skip to content

Commit

Permalink
feat: Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jlenon7 committed Oct 17, 2021
1 parent d7d0b58 commit eb05ef1
Show file tree
Hide file tree
Showing 14 changed files with 13,723 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# editorconfig.org
root = true

[*]
indent_size = 2
indent_style = space
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
Binary file added .github/intl.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: CD Intl

on:
push:
branches:
- main

jobs:
build:

runs-on: ubuntu-18.04

steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- uses: actions/setup-node@v1
with:
node-version: '14.x'
registry-url: 'https://registry.npmjs.org'

- name: Download dependencies
run: npm install

- name: Transpile typescript to javascript
run: npm run build

- name: Automatic GitHub Release
uses: justincy/[email protected]
id: release

- name: Publish to NPM Registry
run: npm publish --access public
if: steps.release.outputs.released == 'true'
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
name: Deploy
31 changes: 31 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: CI Intl

on:
pull_request:
branches:
- main

jobs:
build:

runs-on: ubuntu-18.04

steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- uses: actions/setup-node@v1
with:
node-version: '14.x'
registry-url: 'https://registry.npmjs.org'

- name: Download dependencies
run: npm install

- name: Verify project lint and try to fix it
run: npm run lint:fix

- name: Run the tests from project
run: npm run test
123 changes: 123 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
node_modules/
dist/
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

# IDE
.idea
.vscode

# dotenv environment variables file
.env
.env.testing
.env.production
73 changes: 73 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Intl 🌏

> Very simple Intl support for NodeJS Applications
<p>
<img alt="GitHub language count" src="https://img.shields.io/github/languages/count/secjs/intl?style=for-the-badge&logo=appveyor">

<img alt="Repository size" src="https://img.shields.io/github/repo-size/secjs/intl?style=for-the-badge&logo=appveyor">

<img alt="License" src="https://img.shields.io/badge/license-MIT-brightgreen?style=for-the-badge&logo=appveyor">
</p>

The intention behind this repository is to always maintain a viable and simple internationalization package to use in any type of `NodeJS Framework`.

<img src=".github/intl.png" width="200px" align="right" hspace="30px" vspace="100px">

## Installation

> To use the high potential from this package you need to install first this other packages from SecJS,
> it keeps as dev dependency because one day `@secjs/core` will install everything once.
```bash
npm install @secjs/contracts @secjs/exceptions @secjs/utils
```

```bash
npm install @secjs/intl
```

## Usage

### Sntl

> Format messages using json files inside resources/locales folder
> Is extremely important to create the folder resources/locales in the project root,
> and inside you need to create the folders for each language, example: resources/locales/en-us.
> resources/locales/en-us/messages.json
```json
{
"greeting": "Hello!, my name is {{name}}!"
}
```
> resources/locales/pt-br/messages.json
```json
{
"greeting": "Olá!, meu nome é {{name}}!"
}
```

```ts
import { Sntl } from '@secjs/intl'

// First set the defaultLocale and call load,
// to get all files inside resources folder.

// Now you can call Sntl anyware and use as you want.
await new Sntl.setDefaultLocale('en-us').load()

Sntl.formatMessage('messages.greeting', { name: 'João' }) // { message: 'Hello!, my name is João!' }

// Use forLocale to call for a specific locale in runtime
Sntl.forLocale('pt-br').formatMessage('messages.greeting', { name: 'João' }) // { message: 'Olá!, meu nome é João!' }
Sntl.forLocale('en-us').formatMessage('messages.greeting', { name: 'João' }) // { message: 'Hello!, my name is João!' }

// Use changeLocale to change the defaultLocale in runtime
Sntl.changeLocale('pt-br').formatMessage('messages.greeting', { name: 'João' }) // { message: 'Olá!, meu nome é João!' }
```

---

Made with 🖤 by [jlenon7](https://github.com/jlenon7) :wave:
1 change: 1 addition & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './src/Sntl'
Loading

0 comments on commit eb05ef1

Please sign in to comment.