2.2.0 β’ Published 5 months ago
@hammerhq/localization v2.2.0
@hammerhq/localization
- This is a YAML based localisation system that will make your job quite easy
- Just create your language folder and seperate everything in files
- Set your constants in
constants.yaml
and apply to everything
π¦ Installation
$ npm install @hammerhq/logger
π Usage
import { I18n } from "@hammerhq/localization";
/*
options:
directory?: string;
defaultLocale: string;
*/
const parser = new I18n({
defaultLocale: "en",
});
parser.getLocales(); // => [ "en", "tr" ];
parser.getConstant(); // => all constants;
parser.getConstant("owner"); // => "owner" constant;
parser.toJSON(); // => all language data in an object
parser.toJSON({ arg: "this is an argument" }); // => all language data in an object with argument replaced
parser.get("en", "info", "test"); // "test" string in "info" section in "en" folder
parser.get("tr", "messages", "message", { arg: "this is an argument" }); // "message" string in "messages" section in "tr" folder with "arg" argument
π File Structure
locales/constants.yaml
example
owner: barbarbar338
site: "https://hammer.338.rocks"
anotherConstant: this is a constant
locales/{locale}/{section}.yaml
example
withConstant: this string uses %{owner} constant
withArgs: this string uses %{argument} argument and %{anotherArgument} argument
withConstantsAndArguments: this string uses %{simpleArgument} argument and %{site} constant
π Folder Structure
π locales/
ββββ π constants.yaml
ββββ π en
β ββββ π info.yaml
β ββββ π messages.yaml
β ββββ π test.yaml
ββββ π tr
ββββ π info.yaml
ββββ π messages.yaml
ββββ π test.yaml
𧦠Looking For Contributors
We are looking for contributors to actively work on Hammer and to contribute to the repos. There is still lots of work to do. If you are interested in contributing, please join our Discord server. (There will be a surprise for early contributors!)
π License
Copyright Β© 2022 BarΔ±Ε DEMΔ°RCΔ°.
Distributed under the GPL-3.0 License. See LICENSE
for more information.
𧦠Contributing
This repo is open for #hacktoberfest. Feel free to use GitHub's features.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/my-feature
) - Run prettier (
npm run format
) - Commit your Changes (
git commit -m 'my awesome feature my-feature'
) - Push to the Branch (
git push origin feature/my-feature
) - Open a Pull Request
βοΈ Show your support
Give a βοΈ if this project helped you!
βοΈ Contact
- Mail: hammer@338.rocks
- Discord: https://338.rocks/discord
- Website: https://hammer.338.rocks
- Documentation: https://hammer.338.rocks/docs/packages/localization