Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
14,201 additions
and
23,114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,5 +123,6 @@ npm-debug.log | |
####### | ||
/app/configs/config.js | ||
/app/configs/config.ts | ||
/app/configs/config.json | ||
/dist | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/dist | ||
/build | ||
/node_modules | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"server": { "port": 5000 }, | ||
"debug": true, | ||
"language": "en", | ||
"logger": { | ||
"path": { "debug_log": "./logs/debug.log", "error_log": "./logs/errors.log" }, | ||
"language": "en", | ||
"colors": "enabled", | ||
"debug": "enabled", | ||
"info": "enabled", | ||
"warning": "enabled", | ||
"error": "enabled", | ||
"sponsor": "enabled", | ||
"write": "disabled", | ||
"type": "log" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* Run | ||
* ===================== | ||
* | ||
* Start module | ||
* | ||
* @contributors: Patryk Rzucidło [@ptkdev] <support@ptkdev.io> (https://ptk.dev) | ||
* | ||
* @license: MIT License | ||
* | ||
*/ | ||
import m from "@app/functions/module"; | ||
import configs from "@configs/config.json"; | ||
import translate from "@translations/translate"; | ||
import logger from "@app/utils/logger"; | ||
|
||
(async () => { | ||
const { app } = await m({ text: translate("hello", { name: "Boilerplate" }) }); | ||
|
||
logger.info(app()); | ||
logger.debug(configs.debug ? "true" : "false"); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/** | ||
* Translate | ||
* ===================== | ||
* | ||
* @contributors: Patryk Rzucidło [@ptkdev] <support@ptkdev.io> (https://ptk.dev) | ||
* | ||
* @license: MIT License | ||
* | ||
*/ | ||
import configs from "@configs/config.json"; | ||
import translations from "@app/routes/translations"; | ||
import type { TranslateParamsInterface } from "@app/types/translate.type"; | ||
|
||
/** | ||
* Replace Params | ||
* ===================== | ||
* If translation text is: hi {{name}} how are you? | ||
* This function replace {{name}} token with correct value | ||
* | ||
* @param {string} text - text of current phrase to translate (mandatory) | ||
* @param {Object} language_params - object with token to replace, example: {name:"alex"} (mandatory) | ||
* | ||
* @return {string} text - text with replaced token | ||
* | ||
*/ | ||
const replaceParams = (text: string, language_params: TranslateParamsInterface): string => { | ||
for (const [key, value] of Object.entries(language_params)) { | ||
text = text.replace(`{{${key}}}`, value); | ||
} | ||
|
||
return text; | ||
}; | ||
|
||
/** | ||
* Check | ||
* ===================== | ||
* Check if exist translation in selected language, if not exist get string of phrase from "en" translation | ||
* | ||
* @param {string} language_id - key of translation phrase from /translations/*.json (mandatory) | ||
* | ||
* @return {string} text - text of available translation | ||
* | ||
*/ | ||
const check = (language_id: string): string => { | ||
return translations[configs.language] && translations[configs.language][language_id] | ||
? translations[configs.language][language_id] | ||
: translations["en"][language_id]; | ||
}; | ||
|
||
/** | ||
* Translate | ||
* ===================== | ||
* Get correct translation | ||
* | ||
* @param {string} language_id - key of translation phrase from /translations/*.json (mandatory) | ||
* @param {Object} language_params - object with token to replace, example: {name:"alex"} (optional) | ||
* | ||
* @return {string} text - text of available translation | ||
* | ||
*/ | ||
const translate = (language_id: string, language_params?: TranslateParamsInterface): string => { | ||
let text = ""; | ||
text = check(language_id); | ||
if (language_params) { | ||
text = replaceParams(text, language_params); | ||
} | ||
|
||
return text; | ||
}; | ||
|
||
export { translate }; | ||
export default translate; |
Oops, something went wrong.