{"id":13801326,"url":"https://github.com/xitrum-framework/scala-xgettext","last_synced_at":"2026-01-05T07:59:06.309Z","repository":{"id":6207478,"uuid":"7438478","full_name":"xitrum-framework/scala-xgettext","owner":"xitrum-framework","description":"Scala compiler plugin that acts like GNU xgettext command to extract i18n strings in Scala source code files to Gettext .po file","archived":false,"fork":false,"pushed_at":"2021-01-17T01:44:53.000Z","size":2043,"stargazers_count":25,"open_issues_count":3,"forks_count":11,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-11-18T16:57:25.400Z","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.rst","contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-01-04T10:12:48.000Z","updated_at":"2022-09-23T08:57:53.000Z","dependencies_parsed_at":"2022-08-26T01:23:44.589Z","dependency_job_id":null,"html_url":"https://github.com/xitrum-framework/scala-xgettext","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xitrum-framework%2Fscala-xgettext","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xitrum-framework%2Fscala-xgettext/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xitrum-framework%2Fscala-xgettext/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xitrum-framework%2Fscala-xgettext/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xitrum-framework","download_url":"https://codeload.github.com/xitrum-framework/scala-xgettext/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253932803,"owners_count":21986448,"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.615Z","updated_at":"2026-01-05T07:59:06.267Z","avatar_url":"https://github.com/xitrum-framework.png","language":"Scala","funding_links":[],"categories":["Table of Contents","i18n"],"sub_categories":["i18n"],"readme":".. image:: poedit.png\n\nThis is a Scala 2.11, and 2.12 compiler plugin that acts like GNU ``xgettext``\ncommand to extract i18n strings in Scala source code files to `Gettext \u003chttp://en.wikipedia.org/wiki/Gettext\u003e`_\n.po file, when you compile the Scala source code files.\n\nMore info on Scala compiler plugin:\nhttp://www.scala-lang.org/node/140\n\nPresentation:\n`I18nize Scala programs à la gettext \u003chttp://www.slideshare.net/ngocdaothanh/i18nize-scala-program-a-la-gettext\u003e`_\n\nDiscussion group:\nhttps://groups.google.com/group/scala-xgettext\n\nFor `Play \u003chttps://www.playframework.com/\u003e`_:\nhttps://github.com/georgeOsdDev/play-xgettext\n\nUsage\n-----\n\nThis plugin can be used by frameworks like `Xitrum \u003chttp://xitrum-framework.github.io/\u003e`_\nto add i18n feature to them. For an example, see `this SBT project \u003chttps://github.com/xitrum-framework/comy\u003e`_.\n\nCreate I18n trait or class\n~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nIn your Scala source code, you need to mark the strings you want to extract by\nusing a trait or class that has these method signatures:\n\n::\n\n  t(singular: String): String\n  tn(singular: String, plural: String, n: Long): String\n\n  tc(context: String, singular: String): String\n  tcn(context: String, singular: String, plural: String, n: Long): String\n\nThe methods can also be:\n\n::\n\n  t(singular: String, args: Any*): String\n  tn(singular: String, plural: String, n: Long, args: Any*): String\n\n  tc(context: String, singular: String, args: Any*): String\n  tcn(context: String, singular: String, plural: String, n: Long, args: Any*): String\n\nThat is, only the first arguments (1 first argument for ``t``, 3 first arguments\nfor ``tn`` etc.) are required, all the following arguments are ignored\n(like `params` above).\n\nYou can use `Scaposer \u003chttps://github.com/xitrum-framework/scaposer\u003e`_ to\nimplement the methods above. See `example \u003chttps://github.com/xitrum-framework/xitrum/blob/master/src/main/scala/xitrum/I18n.scala\u003e`_.\n\nThen in your Scala source code, use them like this:\n\n::\n\n  t(\"Hello World\")\n  t(\"Hello %s\").format(\"World\")\n\n  t(\"%,.3f\").format(1234.5678)                                // =\u003e 1,234.568\n  t(\"%,.3f\").formatLocal(java.util.Locale.FRANCE, 1234.5678)  // =\u003e 1 234,568\n\nIf you have more than one placeholder:\n\n::\n\n  // 1$ and 2$ are placeholders\n  t(\"%1$s says hello to %2$s, then %2$s says hello back to %1$s\").format(\"Bill\", \"Hillary\")\n\n  // {0} and {1} are placeholders\n  java.text.MessageFormat.format(t(\"{0} says hello to {1}, then {1} says hello back to {0}\"), \"Bill\", \"Hillary\")\n\n**Important: The arguments ``singular``, ``plural``, and ``context`` MUST be literal constant string, like in the above\nexamples. Otherwise exception will be thrown during compilation. Alternatively, one can add the option\n``ignoreNonLiteralStrings:true`` to ignore those cases instead of throwing an exception**\n\nExtract i18n strings to .pot file\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nTo extract i18n strings like \"Hello World\" in the above snippet:\n\n* Clean your Scala project to force the recompilation of all Scala source code files.\n* Create an empty i18n.pot file in the current working directory. It will be\n  filled with i18n string resources extracted from compiled Scala source code files.\n* Compile your Scala project with ``-P:xgettext:\u003ci18n trait or class\u003e`` option.\n  Example: ``-P:xgettext:xitrum.I18n``.\n\nIf you use `SBT \u003chttp://www.scala-sbt.org/\u003e`_, build.sbt should look like this:\n\n::\n\n  ...\n  autoCompilerPlugins := true\n  addCompilerPlugin(\"tv.cntt\" %% \"xgettext\" % \"1.5.1\")\n  scalacOptions += \"-P:xgettext:xitrum.I18n\"\n  ...\n\nCopy or rename the .pot file to a .po file, and translate the strings in it to\nthe language if want. \"t\" in \".pot\" means \"template\".\n\nYou can use plain text editor to edit the .po file, or you can use\n`Poedit \u003chttp://poedit.net/\u003e`_. Poedit is very convenient, it can merge new .pot\nfile to existing translated .po file.\n\nContent of the .pot file is sorted by msgid, so that it's easier too see diffs\nbetween versions of the .pot/.po file.\n\nConfigure i18n marker method names\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n``t``, ``tn``, ``tc``, and ``tcn`` above are the defaults.\n\nIf you want to use other names, you can change them to, for example,\n``tr``, ``trn``, ``trc``, and ``trcn``, by adding options to Scala compiler:\n\n::\n\n  scalacOptions ++= Seq(\n    \"xitrum.I18n\", \"t:tr\", \"tn:trn\", \"tc:trc\", \"tcn:trcn\"\n  ).map(\"-P:xgettext:\" + _)\n\nIf you skip an option, its default value will be used.\n\nMultiple marker method names\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nMultiple marker methods for ``t`` can be configured like this:\n\n::\n\n  scalacOptions ++= Seq(\n    \"xitrum.I18n\", \"t:tr\", \"t:notr\"\n  ).map(\"-P:xgettext:\" + _)\n\nSimilar for ``tn``, ``tc``, and ``tcn``.\n\nWith this feature you can, for example, create an i18n library that can display\nboth original strings and translated strings.\n\nExplicitly specifying the plural forms for the template\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nSome translation software require the plural forms formula used in the template\nto be explicitly stated.\n\n::\n\n  scalacOptions ++= \"-P:xgettext:sourceLang:en\"\n\nOr:\n\n::\n\n  scalacOptions ++= \"-P:xgettext:rawPluralForm:\u003cnplurals=#; formula\u003e\"\n\nUsing one of these options will cause the template to have a Plural-Forms header.\nMany languages are supported, but see ``src/main/scala/scala/PluralForms.scala``\nfor all of the languages supported and examples of the common formulas.\n\nOmitting this option will omit a Plural-Forms header from the template output.\n\nLoad .po file\n~~~~~~~~~~~~~\n\nUse `Scaposer \u003chttps://github.com/xitrum-framework/scaposer\u003e`_.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxitrum-framework%2Fscala-xgettext","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxitrum-framework%2Fscala-xgettext","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxitrum-framework%2Fscala-xgettext/lists"}