{"id":15445352,"url":"https://github.com/bgmp/alltranslations","last_synced_at":"2025-07-09T20:09:05.374Z","repository":{"id":161005003,"uuid":"626953829","full_name":"BGMP/AllTranslations","owner":"BGMP","description":"The simplest localisation framework for your Java projects!","archived":false,"fork":false,"pushed_at":"2024-02-01T13:51:13.000Z","size":74,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-19T21:38:20.328Z","etag":null,"topics":["i18n","java","maven","translations"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BGMP.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":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-12T13:45:02.000Z","updated_at":"2024-02-12T15:31:50.000Z","dependencies_parsed_at":null,"dependency_job_id":"e175fad3-2b37-4154-8137-3b96e532b610","html_url":"https://github.com/BGMP/AllTranslations","commit_stats":{"total_commits":28,"total_committers":2,"mean_commits":14.0,"dds":0.0357142857142857,"last_synced_commit":"cb58309f56ef1d113b7ca651c61354f6709c7f95"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/BGMP/AllTranslations","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BGMP%2FAllTranslations","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BGMP%2FAllTranslations/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BGMP%2FAllTranslations/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BGMP%2FAllTranslations/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BGMP","download_url":"https://codeload.github.com/BGMP/AllTranslations/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BGMP%2FAllTranslations/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264502621,"owners_count":23618658,"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":["i18n","java","maven","translations"],"created_at":"2024-10-01T19:44:44.388Z","updated_at":"2025-07-09T20:09:05.355Z","avatar_url":"https://github.com/BGMP.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AllTranslations [![build](https://github.com/BGMP/AllTranslations/actions/workflows/build.yml/badge.svg)](https://github.com/BGMP/AllTranslations/actions/workflows/build.yml) [![test](https://github.com/BGMP/AllTranslations/actions/workflows/test.yml/badge.svg)](https://github.com/BGMP/AllTranslations/actions/workflows/test.yml)\n\n\u003cimg align=\"right\" width=\"170\" height=\"170\" src=\"https://user-images.githubusercontent.com/26081543/232375880-516c6c17-bf49-4463-92ed-43dd1b4f7647.png\" alt=\"\"\u003e\n\n**AllTranslations** is a very simple localisation framework for your Java projects!\n\nEver wanted to add support for multiple languages to your Java applications without having to introduce a ton of\ncomplexity to your codebase? Well, AllTranslations might just be what you were looking for!\n\nThis framework offers a very simplistic approach to handling localisation via [.properties](https://en.wikipedia.org/wiki/.properties)\nfiles, and supports all [ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes#Table_of_all_possible_two_letter_codes) and\n[ISO 3166-2](https://en.wikipedia.org/wiki/ISO_3166-2) recognised combinations.\n\nTable of Contents\n===\n* [Installation](#installation)\n  * [Maven](#maven)\n* [Structure](#structure)\n* [Usage](#usage)\n* [Translation Arguments](#translation-arguments)\n* [Nested Translations](#nested-translations)\n* [Missing Translations](#missing-translations)\n\n## Installation\n### Maven\n\n```xml\n\u003crepository\u003e\n  \u003cid\u003egithub\u003c/id\u003e\n  \u003curl\u003ehttps://maven.pkg.github.com/BGMP/AllTranslations\u003c/url\u003e\n\u003c/repository\u003e\n```\n\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003ecl.bgm\u003c/groupId\u003e\n  \u003cartifactId\u003eAllTranslations\u003c/artifactId\u003e\n  \u003cversion\u003e1.0.0-SNAPSHOT\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n## Structure\nOnce you have installed AllTranslations, create a new directory named `i18n/` within your `resources/` folder. Here\nis where all the locale files will live in, along with the template strings file.\n\nHere is how the structure should look like in your project:\n```\nresources/\n└── i18n/\n    ├── en_uk.properties (locale)\n    ├── es_es.properties (locale)\n    ├── strings.properties (templates)\n    └── ge.properties (locale)\n```\n\nThe `strings.properties` file will contain all your base strings (English, US), and the rest of properties files\nrepresent all the available languages for your project. The name of these files consists of a language code, and a\ncountry code (if required). Both of these codes follow ISO conventions:\n  * Language Codes: [ISO 3166-2](https://en.wikipedia.org/wiki/ISO_3166-2)\n  * Country Codes: [ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes)\n\n## Usage\nAllTranslations will require you to have a basic object designed to represent your end user or client you wish to\noffer translations for. In this example, a simple `User` object has been created as follows:\n\n```java\npublic class User {\n  private String name;\n  private String locale;\n\n  public User(String name, String locale) {\n    this.name = name;\n    this.locale = locale;\n  }\n\n  public String getName() {\n    return name;\n  }\n\n  public String getLocale() {\n    return locale;\n  }\n\n  public void setLocale(String locale) { \n    this.locale = locale;\n  }\n}\n```\n\nThen, create a class which will serve all of your translations, extending AllTranslations. The generic object you\nprovide to AllTranslations will be that of your end user as explained above. Following the `User` example, it would\nlook as follows:\n```java\nimport java.util.Locale;\n\npublic class Translations extends AllTranslations\u003cUser\u003e {\n  @Override\n  public Locale getLocale(User user) {\n    return Locale.forLanguageTag(user.getLocale());\n  }\n\n  @Override\n  public void setLocale(User user, Locale locale) {\n    user.setLocale(locale.toLanguageTag());\n  }\n}\n```\n\nCreate your locale files...\n```properties\n# resources/i18n/strings.properties\nmain.welcome = Welcome, {0}!\n```\n\n```properties\n# resources/i18n/es_es.properties\nmain.welcome = Bienvenido, {0}!\n```\n\nFinally, use the framework! Here's a very basic example of how to use AllTranslations:\n\n```java\nimport java.util.Locale;\n\npublic class AllTranslationsExample {\n  public static void main(String[] args) {\n    Translations translations = new Translations();\n\n    User user1 = new User(\"Steve\", \"en_us\");\n    User user2 = new User(\"José\", \"es_es\");\n\n    System.out.println(\"To user1: \" + translations.get(\"main.welcome\", user1, user1.getName()));\n    System.out.println(\"To user2: \" + translations.get(\"main.welcome\", user2, user2.getName()));\n  }\n}\n```\n\nOutput:\n```\nTo user1: Welcome, Steve!\nTo user2: Benvenido, José!\n```\n\n## Translation Arguments\nAs you may have noticed in the example presented above, AllTranslations supports translation arguments by default.\nAt your locale file, simply name them `{0}, {1}, {2}`, etc. respectively, and then you may trail everything you want to\nreplace them with using the `AllTranslations#get()` method.\n\nFor example, given the string `main.arguments = Their names are {0} and {1}.`, you may replace the arguments `{0}` and\n`{1}` as follows:\n```java\npublic class AllTranslationsExample {\n  public static void main(String[] args) {\n    Translations translations = new Translations();\n    String translation = translations.get(\"main.arguments\", \"en_us\", \"Steve\", \"José\");\n    System.out.println(translation);\n  }\n}\n```\n\nOutput:\n```\nTheir names are Steve and José.\n```\n\n## Nested Translations\nTranslations may also be nested by using the `Translatable` object. Simply pass it as any other argument to the\n`Translations#get()` method:\n\n```properties\nnested.string = You have {0} {1}.\nnested.liter = liter\nnested.liters = liters\n```\n\n```java\nimport cl.bgm.Translatable;\n\npublic class AllTranslationsExample {\n  public static void main(String[] args) {\n    Translations translations = new Translations();\n\n    int liters = Math.random() * 10;\n    String translation = translations.get(\"nested.string\", \"en_us\", liters, liters == 1 ? Translatable.of(\"nested.liter\") : Translatable.of(\"nested.liters\"));\n\n    System.out.println(translation);\n  }\n}\n```\n\n`Translatable#of()` also allows trailing arguments to be passed in, so you can infinitely nest translations! \n\n## Missing Translations\nAs in any other translations project, there will be instances where a translation will not be available just yet in one\nlanguage or another. In these cases, AllTranslations will default to your template strings in case it doesn't find a\nsuitable translation in a specific locale file.\n\nOn the other hand, if you request a translation from a locale which doesn't have a corresponding file within the `i18n/`\ndirectory, AllTranslations will also default the string key to your template strings.\n\nIn case the string key you request isn't available in any locale file, or the template strings, the return value for\n`Translations#get()` will be `null`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbgmp%2Falltranslations","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbgmp%2Falltranslations","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbgmp%2Falltranslations/lists"}