{"id":16224272,"url":"https://github.com/camertron/tmx-parser","last_synced_at":"2025-03-19T12:30:40.519Z","repository":{"id":28590495,"uuid":"32108670","full_name":"camertron/tmx-parser","owner":"camertron","description":"Parser for the Translation Memory eXchange (.tmx) file format.","archived":false,"fork":false,"pushed_at":"2015-07-24T18:49:22.000Z","size":164,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-02-28T18:39:43.300Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/camertron.png","metadata":{"files":{"readme":"README.md","changelog":"History.txt","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-03-12T23:20:41.000Z","updated_at":"2024-03-27T08:17:16.000Z","dependencies_parsed_at":"2022-09-03T17:31:00.624Z","dependency_job_id":null,"html_url":"https://github.com/camertron/tmx-parser","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/camertron%2Ftmx-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/camertron%2Ftmx-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/camertron%2Ftmx-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/camertron%2Ftmx-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/camertron","download_url":"https://codeload.github.com/camertron/tmx-parser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243989576,"owners_count":20379648,"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-10-10T12:23:44.894Z","updated_at":"2025-03-19T12:30:40.204Z","avatar_url":"https://github.com/camertron.png","language":"Ruby","readme":"tmx-parser\r\n=================\r\n\r\nParser for the Translation Memory eXchange (.tmx) file format.\r\n\r\n## Installation\r\n\r\n`gem install tmx-parser`\r\n\r\n## Usage\r\n\r\n```ruby\r\nrequire 'tmx-parser'\r\n```\r\n\r\n## Functionality\r\n\r\nGot a .tmx file you need to parse? Just use the `TmxParser#load` method. It'll return an enumerable `TmxParser::Document` object for your iterating pleasure:\r\n\r\n```ruby\r\ndoc = TmxParser.load(File.open('path/to/my.tmx'))\r\ndoc.each do |unit|\r\n  ...\r\nend\r\n```\r\n\r\nYou can also pass a string to `#load`:\r\n\r\n```ruby\r\ndoc = TmxParser.load(File.read('path/to/my.tmx'))\r\n```\r\n\r\nThe parser works in a streaming fashion, meaning it tries not to hold the entire source document in memory all at once. It will instead yield each translation unit incrementally.\r\n\r\n## Translation Units\r\n\r\nTranslation units are simple Ruby objects that contain properties (tmx `\u003cprop\u003e` elements) and variants (tmx `tuv` elements). You can also retrieve the tuid (translation unit id) and segtype (segment type). Given this document:\r\n\r\n```xml\r\n\u003ctmx version=\"1.4\"\u003e\r\n  \u003cbody\u003e\r\n    \u003ctu tuid=\"79b371014a8382a3b6efb86ec6ea97d9\" segtype=\"block\"\u003e\r\n      \u003cprop type=\"x-segment-id\"\u003e0\u003c/prop\u003e\r\n      \u003cprop type=\"x-some-property\"\u003esix.hours\u003c/prop\u003e\r\n      \u003ctuv xml:lang=\"en-US\"\u003e\u003cseg\u003e6 hours\u003c/seg\u003e\u003c/tuv\u003e\r\n      \u003ctuv xml:lang=\"de-DE\"\u003e\u003cseg\u003e6 Stunden\u003c/seg\u003e\u003c/tuv\u003e\r\n    \u003c/tu\u003e\r\n  \u003c/body\u003e\r\n\u003c/tmx\u003e\r\n```\r\n\r\nHere's what you can do:\r\n\r\n```ruby\r\ndoc.each do |unit|\r\n  unit.tuid     # =\u003e \"79b371014a8382a3b6efb86ec6ea97d9\"\r\n  unit.segtype  # =\u003e \"block\"\r\n\r\n  unit.properties.keys                   # =\u003e [\"x-segment-id\", \"x-some-property\"]\r\n  unit.properties['x-segment-id'].value  # =\u003e \"0\"\r\n\r\n  variant = unit.variants.first\r\n  variant.locale    # =\u003e \"en-US\"\r\n  variant.elements  # =\u003e [\"6 hours\"]\r\nend\r\n```\r\n\r\n## Placeholders\r\n\r\nLet's consider a different document:\r\n\r\n```xml\r\n\u003ctmx version=\"1.4\"\u003e\r\n  \u003cbody\u003e\r\n    \u003ctu tuid=\"#{tuid}\" segtype=\"block\"\u003e\r\n      \u003cprop type=\"x-segment-id\"\u003e0\u003c/prop\u003e\r\n      \u003ctuv xml:lang=\"en-US\"\u003e\r\n        \u003cseg\u003e\u003cph type=\"x-placeholder\"\u003e{0}\u003c/ph\u003e sessions\u003c/seg\u003e\r\n      \u003c/tuv\u003e\r\n      \u003ctuv xml:lang=\"de-DE\"\u003e\r\n        \u003cseg\u003e\u003cph type=\"x-placeholder\"\u003e{0}\u003c/ph\u003e Einheiten\u003c/seg\u003e\r\n      \u003c/tuv\u003e\r\n    \u003c/tu\u003e\r\n  \u003c/body\u003e\r\n\u003c/tmx\u003e\r\n```\r\n\r\nThe placeholders will be added to the variant's `elements` array:\r\n\r\n```ruby\r\ndoc.each do |unit|\r\n  variant = unit.variants.first\r\n  variant.elements  # =\u003e [\"#\u003cTmxParser::Placeholder:0x5ad5be4a @text=\"{0}\", @type=\"x-placeholder\"\u003e\", \" sessions\"]\r\nend\r\n```\r\n\r\nBegin paired tags (tmx `bpt` elements) and end paired tags (tmx `ept` elements) are handled the same way.\r\n\r\n## See Also\r\n\r\n* TMX file format: [http://www.gala-global.org/oscarStandards/tmx/tmx14b.html](http://www.gala-global.org/oscarStandards/tmx/tmx14b.html)\r\n\r\n## Requirements\r\n\r\nNo external requirements.\r\n\r\n## Running Tests\r\n\r\n`bundle exec rspec` should do the trick :)\r\n\r\n## Authors\r\n\r\n* Cameron C. Dutro: http://github.com/camertron\r\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcamertron%2Ftmx-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcamertron%2Ftmx-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcamertron%2Ftmx-parser/lists"}