{"id":13801333,"url":"https://github.com/xitrum-framework/scaposer","last_synced_at":"2025-05-13T11:31:03.937Z","repository":{"id":1630708,"uuid":"2352616","full_name":"xitrum-framework/scaposer","owner":"xitrum-framework","description":"GNU Gettext .po file loader for Scala","archived":false,"fork":false,"pushed_at":"2023-12-18T18:08:10.000Z","size":3324,"stargazers_count":38,"open_issues_count":4,"forks_count":6,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-11-18T16:57:24.938Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://www.slideshare.net/ngocdaothanh/i18nize-scala-program-a-la-gettext","language":"Scala","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/xitrum-framework.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG","contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS"}},"created_at":"2011-09-09T01:02:13.000Z","updated_at":"2022-12-15T19:02:39.000Z","dependencies_parsed_at":"2024-01-05T21:57:11.985Z","dependency_job_id":null,"html_url":"https://github.com/xitrum-framework/scaposer","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xitrum-framework%2Fscaposer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xitrum-framework%2Fscaposer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xitrum-framework%2Fscaposer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xitrum-framework%2Fscaposer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xitrum-framework","download_url":"https://codeload.github.com/xitrum-framework/scaposer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253932806,"owners_count":21986449,"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":[],"created_at":"2024-08-04T00:01:21.712Z","updated_at":"2025-05-13T11:31:02.732Z","avatar_url":"https://github.com/xitrum-framework.png","language":"Scala","readme":".. image:: poedit.png\n\nScaposer is a GNU gettext po file parser written in Scala.\nIt's strange that there's not many JVM libraries of this kind, see the\n`discussion on Stackoverflow \u003chttp://stackoverflow.com/questions/4635721/is-there-a-java-library-for-parsing-gettext-po-files\u003e`_.\n\nTo extract i18n strings from Scala source code files, use\n`Scala xgettext \u003chttps://github.com/xitrum-framework/scala-xgettext\u003e`_.\n\nPresentation:\n`I18nize Scala programs à la gettext \u003chttp://www.slideshare.net/ngocdaothanh/i18nize-scala-program-a-la-gettext\u003e`_\n\nDiscussion group: https://groups.google.com/group/scala-xgettext\n\nBasic usage\n-----------\n\nSee `Scaladoc \u003chttp://xitrum-framework.github.io/scaposer/\u003e`_.\n\n::\n\n  val po = \"\"\"\n  msgid \"Hello\"\n  msgstr \"Bonjour\"\n  \"\"\"\n\n  val result = scaposer.Parser.parse(po)\n  // =\u003e An Either,\n  // Left(scaposer.ParseFailure) or\n  // Right(Seq[scaposer.Translation])\n\nUse ``t`` methods to get the translations:\n\n::\n\n  val translations = result.right.get\n  val i18n         = scaposer.I18n(translations)\n  i18n.t(\"Hello\")  // =\u003e \"Bonjour\"\n\nIf there's no translation, or the translation is an empty string\n(not translated yet), the original input is returned:\n\n::\n\n  i18n.t(\"Hi\")  // =\u003e \"Hi\"\n\nContext\n-------\n\n::\n\n  val po = \"\"\"\n  msgid \"Hello\"\n  msgstr \"Bonjour\"\n\n  msgctxt \"Casual\"\n  msgid \"Hello\"\n  msgstr \"Salut\"\n  \"\"\"\n\n  val translations = scaposer.Parser.parse(po).right.get\n  val i18n         = scaposer.I18n(translations)\n  i18n.tc(\"Casual\", \"Hello\")  // =\u003e \"Salut\"\n\nIf there's no translation for the context, the translation without context is tried:\n\n::\n\n  i18n.tc(\"Missing context\", \"Hello\")  // =\u003e \"Bonjour\"\n\n\nPlural-Forms\n------------\n\n::\n\n  val po = \"\"\"\n  msgid \"\"\n  msgstr \"Plural-Forms: nplurals=2; plural=n\u003e1;\"\n\n  msgid \"I have one apple\"\n  msgid_plural \"I have %d apples\"\n  msgstr[0] \"J'ai une pomme\"\n  msgstr[1] \"J'ai %d pommes\"\n  \"\"\"\n\n  val translations = scaposer.Parser.parse(po).right.get\n  val i18n         = scaposer.I18n(translations)\n  i18n.tn(\"I have one apple\", \"I have %d apples\", 1)                // =\u003e \"J'ai une pomme\"\n  i18n.tn(\"I have one apple\", \"I have %d apples\", 2)                // =\u003e \"J'ai %d pommes\"\n  i18n.tcn(\"A context\", \"I have one apple\", \"I have %d apples\", 3)  // =\u003e \"J'ai %d pommes\"\n\nFor performance, your po file should define ``Plural-Forms`` exactly as at:\n\n* http://www.gnu.org/software/gettext/manual/html_node/Plural-forms.html#Plural-forms\n* http://www.gnu.org/software/gettext/manual/html_node/Translating-plural-forms.html#Translating-plural-forms\n\nOtherwise, Scaposer cannot compare the plural form string, and it needs to parse and evaluate (slower).\n\nMerge Po objects\n----------------\n\nYou can merge multiple ``I18n``s together.\n\n::\n\n  val i18n4 = i18n1 ++ i18n2 ++ i18n3\n\nJust like when you merge maps, translations in i18n3 will overwrite those in\ni18n2 will overwrite those in i18n1.\n\nUse with SBT\n------------\n\nSupported Scala versions: 2.11-2.13\n\nbuild.sbt example:\n\n::\n\n  libraryDependencies += \"tv.cntt\" %% \"scaposer\" % \"1.11.1\"\n\nScaposer is used in `Xitrum web framework \u003chttps://github.com/xitrum-framework/xitrum\u003e`_.\n","funding_links":[],"categories":["Table of Contents","i18n"],"sub_categories":["i18n"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxitrum-framework%2Fscaposer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxitrum-framework%2Fscaposer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxitrum-framework%2Fscaposer/lists"}