{"id":19325519,"url":"https://github.com/tiaansu/jsonlang","last_synced_at":"2025-02-24T06:17:09.362Z","repository":{"id":173548847,"uuid":"569638654","full_name":"Tiaansu/JSONLang","owner":"Tiaansu","description":"Provides a simple API for multi-language systems.","archived":false,"fork":false,"pushed_at":"2022-11-23T10:06:22.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-06T06:43:40.146Z","etag":null,"topics":["language","multi-language-systems","open-mp","pawn-library","pawn-package","sa-mp","sa-mp-library"],"latest_commit_sha":null,"homepage":"","language":"Pawn","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Tiaansu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-11-23T09:33:34.000Z","updated_at":"2022-11-26T10:56:50.000Z","dependencies_parsed_at":null,"dependency_job_id":"08ebf38f-974b-4f55-a07f-0e70b77f43a8","html_url":"https://github.com/Tiaansu/JSONLang","commit_stats":null,"previous_names":["tiaansu/jsonlang"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tiaansu%2FJSONLang","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tiaansu%2FJSONLang/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tiaansu%2FJSONLang/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tiaansu%2FJSONLang/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Tiaansu","download_url":"https://codeload.github.com/Tiaansu/JSONLang/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240427327,"owners_count":19799471,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["language","multi-language-systems","open-mp","pawn-library","pawn-package","sa-mp","sa-mp-library"],"created_at":"2024-11-10T02:10:16.501Z","updated_at":"2025-02-24T06:17:09.341Z","avatar_url":"https://github.com/Tiaansu.png","language":"Pawn","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JSONLang\n\n[![sampctl](https://img.shields.io/badge/sampctl-JSONLang-2f2f2f.svg?style=for-the-badge)](https://github.com/Tiaansu/JSONLang)\n\n## Dependencies\n* [YSI](https://github.com/pawn-lang/YSI-Includes)\n* [samp-logger](https://github.com/Southclaws/samp-logger)\n* [strlib](https://github.com/oscar-broman/strlib)\n* [pawn-map](https://github.com/BigEti/pawn-map)\n* [pawn-fsutil](https://github.com/Southclaws/pawn-fsutil)\n* [pawn-json](https://github.com/Southclaws/pawn-json)\n\n## Installation\n\nSimply install to your project:\n\n```bash\nsampctl package install Tiaansu/JSONLang\n```\n\nInclude in your code and begin using the library:\n\n```pawn\n#include \u003cJSONLang\u003e\n```\n\n## Usage\n\nThis package works by loading `json` files from `I18n` folder in the root directory.\n\nThese file should have the same keys, see the [`I18n`](https://github.com/Tiaansu/JSONLang/blob/main/I18n) directory in the repo for an example.\n\n### Loading JSON Languages\n\nTo load a language from a json file, use `InitJsonLanguageFromFile` with just the language filename (including extension), not the full file path. For example `InitJsonLanguageFromFile(\"en-US.lang.json\");` loads the `I18n/en-US.lang.json` file.\n\nYou could also combine this with the [`fsutil`](https://github.com/Southclaws/pawn-fsutil) plugin and iterate through the [`I18n`](https://github.com/Tiaansu/JSONLang/blob/main/I18n) directory.\n\n```pawn\nnew\n    Directory:dir = OpenDir(\"I18n\"),\n    entry[256],\n    ENTRY_TYPE:type,\n    name[64]\n;\n\nwhile (DirNext(dir, type, entry))\n{\n    if (type == E_REGULAR)\n    {\n        PathBase(entry, name);\n\n        InitJsonLanguageFromFile(name);\n    }\n}\n\nCloseDir(dir);\n```\n\nor just by simply using [`InitJsonLanguages()`](https://github.com/Tiaansu/JSONLang/blob/main/JSONLang.inc#118) in `OnGameModeInit`.\n\n### Using JSON Language Strings\n\nNow you've loaded json languages, you can use strings from each json language with the [`GetJsonLanguageString(json_lang_id, const key[], bool:encode = false)`](https://github.com/Tiaansu/JSONLang/blob/main/JSONLang.inc#244) function. The first parameter is the language ID, which you can obtain via name with [`GetJsonLanguageID`](https://github.com/Tiaansu/JSONLang/blob/main/JSONLang.inc#311).\n\nFor Example:\n\n```pawn\nSendClientMessage(playerid, -1, GetJsonLanguageString(GetJsonLanguageID(\"en-US\"), \"greet\"));\n```\n\nWould send the string from `en-US` keyed by `greet`.\n\n### Per-Player Language\n\nYou can store a language ID for each player with [`SetPlayerJsonLanguage`](https://github.com/Tiaansu/JSONLang/blob/main/JSONLang.inc#334) and retrieve it with [`GetPlayerJsonLanguage`](https://github.com/Tiaansu/JSONLang/blob/main/JSONLang.inc#324). For example, your server could display a list of languages in a dialog with [`GetJsonLanguageList`](https://github.com/Tiaansu/JSONLang/blob/main/JSONLang.inc#287) and when the player selects a language, call [`SetPlayerJsonLanguage`](https://github.com/Tiaansu/JSONLang/blob/main/JSONLang.inc#334) with their selection and then in future you can use [`GetPlayerJsonLanguage`](https://github.com/Tiaansu/JSONLang/blob/main/JSONLang.inc#324) to obtain the language ID that player selected.\n\nThere is also a useful macro [`@L(playerid, key[])`](https://github.com/Tiaansu/JSONLang/blob/main/JSONLang.inc#68) which you can use to quickly get a string for a player using their assigned language ID.\n\n```pawn\nSendClientMessage(playerid, -1, @L(playerid, \"greet\"));\n```\n\n## Testing\n\nTo test, simply run the package:\n\n```bash\nsampctl package run\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftiaansu%2Fjsonlang","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftiaansu%2Fjsonlang","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftiaansu%2Fjsonlang/lists"}