{"id":21337753,"url":"https://github.com/freeslave/mofile","last_synced_at":"2026-01-03T04:56:12.180Z","repository":{"id":40605264,"uuid":"132880472","full_name":"FreeSlave/mofile","owner":"FreeSlave","description":"D library for parsing .mo files and getting translated messages","archived":false,"fork":false,"pushed_at":"2021-06-12T11:42:52.000Z","size":60,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-22T14:45:54.351Z","etag":null,"topics":["d","dlang","gettext","i18n"],"latest_commit_sha":null,"homepage":"","language":"D","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsl-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/FreeSlave.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE_1_0.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-05-10T09:44:23.000Z","updated_at":"2023-07-06T17:53:08.000Z","dependencies_parsed_at":"2022-09-04T11:20:52.580Z","dependency_job_id":null,"html_url":"https://github.com/FreeSlave/mofile","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FreeSlave%2Fmofile","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FreeSlave%2Fmofile/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FreeSlave%2Fmofile/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FreeSlave%2Fmofile/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FreeSlave","download_url":"https://codeload.github.com/FreeSlave/mofile/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243814893,"owners_count":20352038,"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":["d","dlang","gettext","i18n"],"created_at":"2024-11-22T00:01:24.395Z","updated_at":"2026-01-03T04:56:12.151Z","avatar_url":"https://github.com/FreeSlave.png","language":"D","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mofile\n\nD library for parsing .mo files and getting translated messages. Support for plural forms is present. Usage is similar to [GNU gettext](https://www.gnu.org/software/gettext/).\n\n[![Build Status](https://github.com/FreeSlave/mofile/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/FreeSlave/mofile/actions/workflows/ci.yml) [![Coverage Status](https://coveralls.io/repos/FreeSlave/mofile/badge.svg?branch=master\u0026service=github)](https://coveralls.io/github/FreeSlave/mofile?branch=master)\n\n[Online documentation](https://freeslave.github.io/mofile/mofile.html)\n\n## Usage\n\n```d\nimport mofile;\n// Parse .mo file\nMoFile moFile = MoFile(\"ru.mo\");\n// Find translation\nstring s = moFile.gettext(\"Hello, world\");\n// Trying out plural forms\ns = moFile.ngettext(\"File\", \"Files\", 1);\ns = moFile.ngettext(\"File\", \"Files\", 3);\ns = moFile.ngettext(\"File\", \"Files\", 5);\n```\n\n## [Example](examples/gettext.d)\n\nCommandline analogue of gettext and ngettext functions.\n\nTo run this example you must have some .mo file.\nFor a quick start there's already [template](examples/messages.pot) and [Russian translation](examples/ru.po) example files, so you only need to generate .mo file:\n\n    msgfmt --no-hash examples/ru.po -o examples/ru.mo\n    # The library currently does not support lookup by hash, so we omit hash generation.\n\nAnd then run:\n\n    dub examples/gettext.d examples/ru.mo \"Hello, world\"\n    dub examples/gettext.d examples/ru.mo \"File\" \"Files\" 1\n    dub examples/gettext.d examples/ru.mo \"File\" \"Files\" 3\n    dub examples/gettext.d examples/ru.mo \"File\" \"Files\" 5\n    dub examples/gettext.d examples/ru.mo \"\" # Get header\n\nGeneric use:\n\n    dub examples/gettext.d $MOFILE msgid # msgid is a string to translate\n    dub examples/gettext.d $MOFILE msgid msgid_plural n # msgid_plural is an untranslated plural form of message, n is a number to calculate a plural form from.\n\n## How to generate .mo file from source file\n\nMostly the same way as in C/C++ projects.\nStep by step process of generation .mo file from source file (gettext utilities must be installed):\n\n    SOURCE=examples/main.d\n    TEMPLATE=examples/messages.pot\n    POFILE=examples/ru.po\n    MOFILE=examples/ru.mo\n    MSGLOCALE=ru_RU.UTF-8 # Target locale\n    xgettext --from-code=UTF-8 --language=C \"$SOURCE\" -o \"$TEMPLATE\" # Create template file.\n    msginit --locale=$MSGLOCALE -i \"$TEMPLATE\" -o \"$POFILE\" --no-translator # Generate text translation file\n    # ... translate messages in editor\n    msgfmt \"$POFILE\" -o \"$MOFILE\" # Generate binary translation file\n\nIf source file has been changed run these commands to update translation files:\n\n    xgettext -j --from-code=UTF-8 --language=C \"$SOURCE\" -o \"$TEMPLATE\" # Update template file.\n    msgmerge --update $POFILE \"$TEMPLATE\"\n    # ... fix translations if needed\n    msgfmt \"$POFILE\" -o \"$MOFILE\"\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffreeslave%2Fmofile","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffreeslave%2Fmofile","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffreeslave%2Fmofile/lists"}