{"id":28407631,"url":"https://github.com/level12/morphi","last_synced_at":"2026-02-27T11:32:32.936Z","repository":{"id":57443217,"uuid":"144869152","full_name":"level12/morphi","owner":"level12","description":"Translations services for applications and libraries","archived":false,"fork":false,"pushed_at":"2025-07-10T12:57:15.000Z","size":2812,"stargazers_count":0,"open_issues_count":4,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-30T03:45:37.603Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/level12.png","metadata":{"files":{"readme":"readme.rst","changelog":"changelog.rst","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,"zenodo":null}},"created_at":"2018-08-15T15:14:46.000Z","updated_at":"2025-07-10T12:57:18.000Z","dependencies_parsed_at":"2024-12-18T15:19:32.696Z","dependency_job_id":"1b2ffdb4-cd1e-46e5-9556-751c00dc6476","html_url":"https://github.com/level12/morphi","commit_stats":{"total_commits":17,"total_committers":3,"mean_commits":5.666666666666667,"dds":"0.47058823529411764","last_synced_commit":"02d08be0ffd6708098d682c82f10ffaf3e5f2fca"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/level12/morphi","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/level12%2Fmorphi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/level12%2Fmorphi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/level12%2Fmorphi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/level12%2Fmorphi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/level12","download_url":"https://codeload.github.com/level12/morphi/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/level12%2Fmorphi/sbom","scorecard":{"id":586105,"data":{"date":"2025-08-11","repo":{"name":"github.com/level12/morphi","commit":"5990b930467b28b6f974d49672f59a18ef85d114"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.3,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Code-Review","score":0,"reason":"Found 2/21 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Maintained","score":4,"reason":"3 commit(s) and 2 issue activity found in the last 90 days -- score normalized to 4","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":9,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Warn: project license file does not contain an FSF or OSI license."],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":8,"reason":"2 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: PYSEC-2022-42969","Warn: Project is vulnerable to: PYSEC-2024-187 / GHSA-rqc4-2hc7-8c8v"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 10 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-20T20:33:15.023Z","repository_id":57443217,"created_at":"2025-08-20T20:33:15.023Z","updated_at":"2025-08-20T20:33:15.023Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29892132,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-27T09:48:51.284Z","status":"ssl_error","status_checked_at":"2026-02-27T09:48:43.992Z","response_time":57,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2025-06-02T01:30:34.623Z","updated_at":"2026-02-27T11:32:32.931Z","avatar_url":"https://github.com/level12.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"morphi\n######\n\nTranslatable text for applications and libraries.\n\nWhat is morphi?\n===============\n\n``morphi`` was born out of the need to create a distributable library with internally-localized\ntext. Although there are several existing packages which deal with translatable text, they all\nseem to focus on standalone applications; there seems to be very little available for working\nwith messages that are distributed along with a packaged library.\n\n\nFoundations\n-----------\n\n``morphi`` is built on ideas gleaned from the following:\n\n * the built-in gettext module\n * Babel\n\n\nTranslation\n===========\n\nThe ``morphi`` module provides utilities for loading ``gettext``-compatible\ntranslators from either the local filesystem or directly from a package. The default\nfinder will first attempt to locate the messages files in the local filesystem (allowing\nmessages to be overridden on a particular system), but, if a package name is given,\nwill then automatically search the package for the messages files. This allows a library\nto store default translation messages within the library package itself, and still have\nthose messages be successfully loaded at runtime.\n\nThe ``morphi`` module is primarily built around the\n`Babel \u003chttp://babel.pocoo.org/en/latest/\u003e`_ package, with\n`speaklater \u003chttps://github.com/mitsuhiko/speaklater\u003e`_ used for lazy lookups.\n\n\nMessage management\n------------------\n\nAs the ``morphi`` module is built on ``Babel``, the standard ``distutils`` commands\nprovided by ``Babel`` are available, and exposed to downstream use. As such, the\nstandard ``extract_messages``, ``init_catalog``, ``update_catalog``, and ``compile_catalog``\ncommands are all present and work as described in the `Babel documentation \u003chttp://babel.pocoo.org/en/latest/setup.html\u003e`_.\n\nIn addition to the standard ``Babel`` ``distutils`` commands, an additional ``compile_json``\ncommand has been added. The ``compile_json`` command will compile the messages into\na JSON file compatible with the\n`gettext.js \u003chttps://github.com/guillaumepotier/gettext.js\u003e`_ javascript library.\n\n\nUsing translations within a library\n-----------------------------------\n\nThe easiest way to use the translations is to utilize the ``Manager`` class, which\nencapsulates the lookups and ``gettext`` methods, and which provides a way of loading\na new messages file after instantiation (allowing the language to be changed after\ninitialization).\n\nAs an example, let's say you're creating a translation-enabled library named 'mylib'.\nThe following might be used to initialize and load the translations for use. Details\nabout the \"locales registry\" can be found below.\n\n.. code-block:: python\n   :name: extensions.py\n\n   # import the translation library\n   from morphi.messages import Manager\n   from morphi.registry import default_registry\n\n   # instantiate the translations manager\n   translation_manager = Manager(package_name='mylib')\n\n   # register the manager with the default locales registry\n   default_registry.subscribe(translation_manager)\n\n   # initialize shorter names for the gettext functions\n   gettext = translation_manager.gettext\n   lazy_gettext = translation_manager.lazy_gettext\n   lazy_ngettext = translation_manager.lazy_ngettext\n   ngettext = translation_manager.ngettext\n\n\nNote that, in general, this code should be executed only a single time for a given\npackage. It is recommended that this code be added to an ``extensions.py`` or similar\nfile, from which the gettext functions can be loaded as singletons.\n\n.. code-block:: python\n\n   from mylib.extensions import gettext as _\n\n   print(_('My translatable text'))\n\n\nFormat variables\n----------------\n\nThe gettext functions all permit additional named parameters, to be used in\nformatting the translated string. The library currently supports new-style ``.format``\ntype formatting.\n\n.. code-block:: python\n\n   print(_('Hello, {name}!', name='World'))\n\n\nLocales Registry\n----------------\n\nParticularly when being used with package-specific translations, the\n``Manager`` will need to be able to be notified when the application's language\nsettings (particularly the locales) are changed, so that the correct messages\ncan be loaded and displayed. In order to simplify this notification,\n``morphi.registry.Registry`` (with a default singleton registry\nnamed ``default_registry``) can be used. Managers can then be subscribed or\nunsubscribed to the registry, which will then notify all managers when\nthe locale information has changed.\n\n.. code-block:: python\n\n   from morphi.registry import default_registry as locales_registry\n\n   locales_registry.locales = 'es'\n\n\nTypically, a manager should be registered with the registry immediately after\nit has been instantiated.\n\n\nJinja Environment\n-----------------\n\nIf using Jinja templates, the Jinja environment should be initialized to add the\ntranslation functions.\n\n.. code-block:: python\n\n   from morphi.helpers.jinja import configure_jinja_environment\n\n   configure_jinja_environment(app.jinja_env, manager)\n\n.. code-block:: jinja\n\n   {{ _('Hello, world!') }}\n\n\nJavaScript translations\n-----------------------\n\nAs mentioned above, a ``compile_json`` ``distutils`` command is added by the library,\nwhich will compile the messages to a ``messages.js``-compatible JSON file. The library\ncan be initialized and used as follows\n\n.. code-block:: html\n   :name: index.html\n\n   \u003cscript src=\"{{url_for('mylib.static', filename='gettext.min.js')}}\"\u003e\u003c/script\u003e\n   \u003cscript\u003e\n       var i18n = window.i18n({});\n       window._ = function(msgid, domain) {\n           return i18n.dcnpgettext.apply(\n               i18n,\n               [domain, undefined, msgid, undefined, undefined].concat(\n                   Array.prototype.slice.call(arguments, 1)\n               )\n           );\n       };\n       {% set json_filename = find_mo_filename(package_name='mylib',\n                                               extension='json',\n                                               localedir='static/i18n') %}\n       {% if json_filename %}\n           {# strip off the leading 'static/' portion of the filename #}\n           {% set json_filename = json_filename[7:] %}\n       $.getJSON(\n           '{{ url_for(\"mylib.static\", filename=json_filename) }}'\n       ).then(function (result) {\n           i18n.loadJSON(result, 'mylib');\n       });\n       {% endif %}\n   \u003c/script\u003e\n\n   . . .\n\n   \u003cp\u003e_('Hello, world!', 'mylib')\u003c/p\u003e\n\n\nNote the presence of the ``find_mo_filename`` function; this function is made available\nby calling the ``configure_jinja_environment`` manager method as described above.\n\n\nInstallation\n============\n\n``morphi`` can be installed via ``pip``:\n\n.. code:: bash\n\n   pip install morphi\n\nTo install for development, simply add the ``develop`` tag:\n\n.. code:: bash\n\n   pip install morphi[develop]\n\n\nDevelopment\n===========\n\nTesting\n-------\n\nTesting currently uses `pytest \u003chttps://docs.pytest.org/en/latest/\u003e`_:\n\n.. code:: bash\n\n   pytest morphi\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flevel12%2Fmorphi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flevel12%2Fmorphi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flevel12%2Fmorphi/lists"}