1.1.3 ā€¢ Published 2 years ago

locale-parser v1.1.3

Weekly downloads
42
License
MIT
Repository
github
Last release
2 years ago

DEPRECATED: Use @hammerhq/localization

~barbarbar338

āœØ Locale Parser by barbarbar338

  • 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

šŸ’” Example

import { I18n } from "locale-parser";

/*
    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://barbarbar338.fly.dev/"
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
1.1.3

2 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago