lang-parser-js
v1.0.0
Published
lang parser
Readme
Lang-parser
Support for .lang files with custom syntax.
Features
- Lightweight and simple parser for
.langfiles. - 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
`ssInitialization
const LangParser = require("lang-parser")
const Language = new LangParser("./your_lang_file.lang", "en-us")- LangParser: The first argument specifies the path to the
.langfile. - 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: nullgetAuthor
Returns the author of the translation.
Example:
console.log(Language.getAuthor()) // Returns: n4styagetLang
Returns the language specified in the .lang file.
Example:
console.log(Language.getLang()) // Returns: en-usThanks
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.
