{"id":18617563,"url":"https://github.com/arashm/poparser","last_synced_at":"2025-06-25T15:07:42.624Z","repository":{"id":16990695,"uuid":"19753718","full_name":"arashm/PoParser","owner":"arashm","description":"A Ruby PO file parser, editor and generator. PO files are translation files generated by GNU/Gettext tool","archived":false,"fork":false,"pushed_at":"2024-05-09T14:27:43.000Z","size":206,"stargazers_count":17,"open_issues_count":2,"forks_count":9,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-06-25T15:07:42.343Z","etag":null,"topics":["gettext","parser","po","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","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/arashm.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","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}},"created_at":"2014-05-13T19:58:21.000Z","updated_at":"2025-01-09T16:32:44.000Z","dependencies_parsed_at":"2024-01-03T14:46:15.683Z","dependency_job_id":null,"html_url":"https://github.com/arashm/PoParser","commit_stats":{"total_commits":184,"total_committers":9,"mean_commits":"20.444444444444443","dds":0.1032608695652174,"last_synced_commit":"505a61612f77817e962e426aad173ad35c0e53a0"},"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"purl":"pkg:github/arashm/PoParser","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arashm%2FPoParser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arashm%2FPoParser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arashm%2FPoParser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arashm%2FPoParser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arashm","download_url":"https://codeload.github.com/arashm/PoParser/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arashm%2FPoParser/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261897003,"owners_count":23226648,"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":["gettext","parser","po","ruby"],"created_at":"2024-11-07T03:41:16.086Z","updated_at":"2025-06-25T15:07:42.599Z","avatar_url":"https://github.com/arashm.png","language":"Ruby","readme":"# PoParser\n\n![Build Status](https://github.com/arashm/poparser/workflows/Ruby/badge.svg?branch=master)\n[![Coverage Status](https://coveralls.io/repos/github/arashm/PoParser/badge.svg)](https://coveralls.io/github/arashm/PoParser)\n[![Code Climate](https://codeclimate.com/github/arashm/PoParser.png)](https://codeclimate.com/github/arashm/PoParser)\n[![Gem Version](https://badge.fury.io/rb/PoParser.svg)](http://badge.fury.io/rb/PoParser)\n\nA Ruby PO file parser, editor and generator. PO files are translation files generated by GNU/Gettext tool. This GEM is compatible with [GNU PO file specification](https://www.gnu.org/software/gettext/manual/html_node/PO-Files.html). report misbehaviours and bugs to the [issue tracker](https://github.com/arashm/PoParser/issues).\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n    gem 'PoParser'\n\nAnd then execute:\n\n    $ bundle install\n\nOr globally install it:\n\n    $ gem install PoParser\n\n## Usage\n\nWorking with the GEM is pretty easy:\n\n```ruby\nrequire 'poparser'\n\ncontent = File.read('example.po')\npo = PoParser.parse(content)\n# =\u003e \u003cPoParser::Po, Translated: 68.1% Untranslated: 20.4% Fuzzy: 11.5%\u003e\n\n# Or you could pass a file path:\n\npath = Pathname.new('example.po')\npo = PoParser.parse_file(path)\n# =\u003e \u003cPoParser::Po, Translated: 68.1% Untranslated: 20.4% Fuzzy: 11.5%\u003e\n```\n\nThe `parse` method returns a `PO` object which contains all `Entries`:\n\n```ruby\n# get all entries\npo.entries # or .all alias\n\n# including cached/obsolete entries (started with \"#~\")\n# more info: https://www.gnu.org/software/gettext/manual/html_node/Obsolete-Entries.html\npo.entries(true)\n\n# get all fuzzy entries\npo.fuzzy\n\n# get all untranslated entries\npo.untranslated\n\n# get all translated entries\npo.translated\n\n# get all cached/obsolete entries\npo.cached # or .obsolete alias\n\n# returns a hash representation of the PO file\npo.to_h\n\n# returns a string representation of the PO file\npo.to_s\n```\n\nYou can add a new entry to the PO file:\n\n```ruby\nnew_entry = {\n              translator_comment: 'comment',\n              reference: 'reference comment',\n              msgid: 'untranslated',\n              msgstr: 'translated string'\n            }\n\npo.add(new_entry)\n\n# There's also an alias for add `\u003c\u003c`\npo \u003c\u003c new_entry\n```\n\nYou can pass an array of hashes to `new_entry` and it will be added to `PO` file.\n\nSimilarly you can add plural strings:\n\n```ruby\nnew_entry = {\n              translator_comment: 'comment',\n              reference: 'reference comment',\n              msgid_plural: 'untranslated',\n              'msgstr[0]': 'translated string',\n              'msgstr[1]': 'translated string'\n            }\n\n```\n\n_Note_: currently `PoParser` won't warn you if you add a `msgstr[0]` without `msgid_plural`, any `msgid` at all or even if the index numbers in `msgstr[0]` are not in any logical order.\n\n### Entry\n\nEach entry can have following properties (for more information see [GNU PO file specification](https://www.gnu.org/software/gettext/manual/html_node/PO-Files.html)):\n\n```\ntranslator_comment\nreference\nextracted_comment\nflag\nprevious_msgctxt\nprevious_msgid\nprevious_msgid_plural\ncached # obsolete entries\nmsgid\nmsgid_plural\nmsgstr\nmsgctxt\n```\n\n#### Working with entries\n\nThe `PO` object contains many `Entry` objects. Number of methods are available to check state of an `Entry`:\n\n```ruby\nentry = po.entries[1]\n\nentry.untranslated? # or .incomplete? alias\n#=\u003e false\nentry.translated? # or .complete? alias\n#=\u003e true\nentry.fuzzy?\n#=\u003e true\nentry.plural?\n#=\u003e false\nentry.cached? # or .obsolete?\n#=\u003e false\n```\n\nYou can get or edit each property of the `Entry`:\n\n```ruby\nentry.msgid.to_s\n#=\u003e \"This is an msgid that needs to get translated\"\nentry.translate(\"This entry is translated\") # or `msgstr=` alias\nentry.msgstr.to_s\n#=\u003e \"This entry is translated\"\n```\n\nNote that msgstr for plural entries are returned as Array:\n\n```ruby\nif entry.plural?\n  entry.msgstr.each do |msgstr|\n    msgstr.to_s\n    #=\u003e This is one of the plural translations\n  end\nend\n```\n\nYou can mark an entry as fuzzy:\n\n```ruby\nentry.flag_as_fuzzy\nentry.fuzzy?\n#=\u003e true\n```\n\nIt's possible to get Hash and String representation of the `Entry`:\n\n```ruby\nentry.to_h\nentry.to_s\n```\n\nTo remove an entry from the PO, use `PO#delete`\n\n```ruby\npo.delete(entry)\n```\n\n### Searching\n\n`PO` is an `Enumerable`. All exciting methods from `Enumerable` are available in `PO`. The `PO` yields `Entry`.\n\n```ruby\npo.find_all do |entry|\n  entry.msgid.str.match(/some text/i)\nend\n```\n\nThere is a helper method that does the same:\n\n```ruby\npo.search_in(:msgstr, 'some string to search')\n```\n\nThis method returns an array of matched entries.\n\n### Saving\n\nYou can simply save the PO file using the `PO` object:\n\n```ruby\npo.save_file\n```\n\nIf you want to save as the file in diffrent location change the `path`:\n\n```ruby\npo.path\n#=\u003e example.po\npo.path = 'example2.po'\npo.save_file\n```\n\n## Header\n\nThe first entry of every PO file is reserved for header which represent license and general information about translators and the po file itself. For more information visit the [GNU website](https://www.gnu.org/software/gettext/manual/html_node/Header-Entry.html#Header-Entry).\n\nGet header with `header`!:\n\n```ruby\npo.header\n```\n\nYou can get and set following variables from `header`:\n\n```\n  pot_creation_date\n  po_revision_date\n  project_id\n  report_to\n  report_msgid_bugs_to\n  last_translator\n  team\n  language\n  charset\n  encoding\n  plural_forms\n```\n\n## To-Do\n\n* Streaming support\n* Update header after changing/saving po\n* add `before_save` and `after_save` callbacks\n\n## Authors\n\n[Arash Mousavi](https://github.com/arashm)\n\n### [Contributors](https://github.com/arashm/PoParser/contributors)\n - [Dennis-Florian Herr](https://github.com/dfherr)\n - [Roland Gropmair](https://github.com/roland9)\n\nLicense: [MIT](https://github.com/arashm/PoParser/blob/master/LICENSE.txt)\n\n## Contributing\n\n1. Fork it ( http://github.com/arashm/poparser/fork )\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farashm%2Fpoparser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farashm%2Fpoparser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farashm%2Fpoparser/lists"}