1.0.0 • Published 6 months ago

lang-parser-js v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
6 months ago

Lang-parser

Support for .lang files with custom syntax.

GitHub license


Features

  • Lightweight and simple parser for .lang files.
  • Supports multi-line strings and variable interpolation.
  • Handles language-specific parsing logic.
  • Detects mismatched languages and warns users.

Installation

Установка на русском

  • NPM: npm install lang.js
  • From Source: Here

Documentation

Документация на русском

File Example

Here is an example of a .lang file:

lang: en-us
author: n4stya

key_1 = "Hello, ${name}!"
key_2 = ss`
This is a 
multiline string
`ss

Initialization

const LangParser = require("lang-parser")
const Language = new LangParser("./your_lang_file.lang", "en-us")
  • LangParser: The first argument specifies the path to the .lang file.
  • language: The second argument is the target language. If it does not match the file, the parser will stop working.

Methods

interpolate

This is a system function. It is not intended for direct usage.

get

Gives a translation using a key.

Example:

const LangParser = require("lang-parser")
const Language = new LangParser("./your_lang_file.lang", "en-us")

console.log(Language.get("key_1", { name: "John" })) // Returns: Hello, John!
console.log(Language.get("non_existing_key")) // Returns: null

getAuthor

Returns the author of the translation.

Example:

console.log(Language.getAuthor()) // Returns: n4stya

getLang

Returns the language specified in the .lang file.

Example:

console.log(Language.getLang()) // Returns: en-us

Thanks

Special thanks to Obzori for helping!


Contributing

We welcome contributions! Feel free to submit pull requests or report issues.


License

This project is licensed under the MIT License. See the LICENSE file for details.

1.0.0

6 months ago