{"id":14235555,"url":"https://github.com/jimmycuadra/to_lang","last_synced_at":"2025-04-12T18:46:02.154Z","repository":{"id":62559220,"uuid":"1131110","full_name":"jimmycuadra/to_lang","owner":"jimmycuadra","description":"Translate Ruby strings and arrays with Google Translate.","archived":false,"fork":false,"pushed_at":"2024-05-10T05:50:32.000Z","size":83,"stargazers_count":294,"open_issues_count":1,"forks_count":13,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-03T20:12:56.790Z","etag":null,"topics":["application","cli","google-translate","language","library","ruby","translation"],"latest_commit_sha":null,"homepage":"http://rubydoc.info/github/jimmycuadra/to_lang/master/frames","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/jimmycuadra.png","metadata":{"files":{"readme":"README.md","changelog":null,"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}},"created_at":"2010-12-02T05:51:25.000Z","updated_at":"2024-10-19T18:23:15.000Z","dependencies_parsed_at":"2024-06-19T04:01:18.053Z","dependency_job_id":"60e58c80-ce35-43a3-b0c6-538c033b2aed","html_url":"https://github.com/jimmycuadra/to_lang","commit_stats":{"total_commits":123,"total_committers":3,"mean_commits":41.0,"dds":"0.13008130081300817","last_synced_commit":"390625e8254733173077d3085669311cb7871f22"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimmycuadra%2Fto_lang","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimmycuadra%2Fto_lang/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimmycuadra%2Fto_lang/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimmycuadra%2Fto_lang/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jimmycuadra","download_url":"https://codeload.github.com/jimmycuadra/to_lang/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248617497,"owners_count":21134191,"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":["application","cli","google-translate","language","library","ruby","translation"],"created_at":"2024-08-20T21:02:04.638Z","updated_at":"2025-04-12T18:46:02.134Z","avatar_url":"https://github.com/jimmycuadra.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"[![Gem Version](https://badge.fury.io/rb/to_lang.png)](http://badge.fury.io/rb/to_lang)\n[![Build Status](https://travis-ci.org/jimmycuadra/to_lang.png?branch=master)](https://travis-ci.org/jimmycuadra/to_lang)\n[![Code Climate](https://codeclimate.com/github/jimmycuadra/to_lang.png)](https://codeclimate.com/github/jimmycuadra/to_lang)\n\n# to_lang\n\n**to_lang** is a Ruby library that adds language translation methods to strings and arrays, backed by the Google Translate API.\n\n## Installation\n\nSimply run:\n\n``` bash\ngem install to_lang\n```\n\n## Usage\n\nTo use **to_lang**, require the library, then call `ToLang.start` with your Google Translate API key. At this point you will have access to all the new translation methods, which take the form `to_language`, where \"language\" is the language you wish to translate to.\n\nGoogle Translate attempts to detect the source language, but you can specify it explicitly by calling methods in the form `to_target_language_from_source_language`, where \"target language\" is the language you are translating to and \"source_language\" is the language you are starting with. An inverted form with equivalent functionality, `from_source_language_to_target_language` is also available. These methods are generated dynamically and will not appear in a calls to `String.instance_methods` or `Array.instance_methods` until they have been called once. Strings and arrays will, however, `respond_to?` these methods prior to their dynamic definition.\n\nThe dynamic methods are simply syntactic sugar for `String#translate` and `Array#translate`, which you can use directly as well.\n\n**to_lang** also comes with a command line utility for quick translations from the shell.\n\n## String Examples\n\nLoad and initialize **to_lang**:\n\n``` ruby\nrequire 'to_lang'\n\nToLang.start('YOUR_GOOGLE_TRANSLATE_API_KEY')\n```\n\nTranslate some text to Spanish:\n\n``` ruby\n\"Very cool gem!\".to_spanish # =\u003e \"Muy fresco joya!\"\n```\n\nA case where the source language is ambiguous:\n\n``` ruby\n\"a pie\".to_spanish # =\u003e \"a pie\"\n\"a pie\".to_spanish_from_english # =\u003e \"un pastel\"\n```\n\nOr equivalently:\n\n``` ruby\n\"a pie\".from_english_to_spanish # =\u003e \"un pastel\"\n```\n\nUsing `String#translate` directly:\n\n``` ruby\n\"hello world\".translate('es') # =\u003e \"hola mundo\"\n\"a pie\".translate('es', :from =\u003e 'en') # =\u003e \"un pastel\"\n```\n\n## Array Examples\n\nArrays can be used to translate a batch of strings in a single method call and a single HTTP request. The exact same methods shown above work for arrays as well. For example, to translate an array of strings to Spanish:\n\n``` ruby\n[\"One\", \"Two\", \"Three\"].to_spanish # =\u003e [\"Uno\", \"Dos\", \"Tres\"]\n```\n\n## Debugging\n\n`translate` also has the advantage of allowing you to get debug output for a translation. `translate` accepts a `:debug` option with three possible values: `:request`, `:response`, and `:all`. `:request` will cause the method to return a hash of the parameters that will be sent to the Google Translate API. `:response` will cause the method to return the full response from the API call as a hash. `:all` will cause the method to return a hash which contains both the request hash and the full response.\n\n``` ruby\n\"hello world\".translate('es', :debug =\u003e :request)\n# =\u003e {:key=\u003e\"my_key\", :q=\u003e\"hello world\", :target=\u003e\"es\"}\n```\n\n``` ruby\n\"hello world\".translate('es', :debug =\u003e :response)\n# =\u003e {\"data\"=\u003e{\"translations\"=\u003e[{\"translatedText\"=\u003e\"hola mundo\", \"detectedSourceLanguage\"=\u003e\"en\"}]}}\n```\n\n``` ruby\n\"hello world\".translate('es', :debug =\u003e :all)\n# =\u003e {:request=\u003e{:key=\u003e\"my_key\", :q=\u003e\"hello world\", :target=\u003e\"es\"},\n#    :response=\u003e{\"data\"=\u003e{\"translations\"=\u003e[{\"translatedText\"=\u003e\"hola mundo\",\n#    \"detectedSourceLanguage\"=\u003e\"en\"}]}}}\n```\n\n## Command Line Interface\n\nThe command line utility `to_lang` has the following interface:\n\n```\nto_lang [--key API_KEY] [--from SOURCE_LANGUAGE] --to DESTINATION_LANGUAGE STRING [STRING, ...]\n```\n\n`to_lang` accepts a space separated list of strings to translate. At least one string is required, as is the `--to` option, which accepts a language code (e.g. \"es\"). `to_lang` will attempt to load a Google Translate API key from the `GOOGLE_TRANSLATE_API_KEY` environment variable. If one is not available, it must be passed in from the command line with the `--key` option. For complete usage instructions, invoke the utility with the `--help` option.\n\nExamples:\n\nA simple translation with the key being passed in directly from the command line:\n\n``` bash\nto_lang --key YOUR_GOOGLE_TRANSLATE_API_KEY --to es \"hello world\"\nhola mundo\n```\n\nWith the key in an environment variable and multiple strings:\n\n``` bash\nto_lang --to es \"hello world\" \"a pie\"\nhola mundo\na pie\n```\n\nSpecifying the source language:\n\n``` bash\nto_lang --from en --to es \"hello world\" \"a pie\"\nhola mundo\nun pastel\n```\n\n## Supported Languages\n\n**to_lang** adds the following methods to strings and arrays. Each of these methods can be called with an explicit source language by appending `_from_source_language` or prepending `from_source_language_` to the method name.\n\n* to_afrikaans\n* to_albanian\n* to_arabic\n* to_belarusian\n* to_bulgarian\n* to_catalan\n* to_simplified_chinese\n* to_traditional_chinese\n* to_croatian\n* to_czech\n* to_danish\n* to_dutch\n* to_english\n* to_estonian\n* to_filipino\n* to_finnish\n* to_french\n* to_galician\n* to_german\n* to_greek\n* to_haitian_creole\n* to_hebrew\n* to_hindi\n* to_hungarian\n* to_icelandic\n* to_indonesian\n* to_irish\n* to_italian\n* to_japanese\n* to_latvian\n* to_lithuanian\n* to_macedonian\n* to_malay\n* to_maltese\n* to_norwegian\n* to_persian\n* to_polish\n* to_portuguese\n* to_romanian\n* to_russian\n* to_serbian\n* to_slovak\n* to_slovenian\n* to_spanish\n* to_swahili\n* to_swedish\n* to_thai\n* to_turkish\n* to_ukrainian\n* to_vietnamese\n* to_welsh\n* to_yiddish\n\n## Documentation\n\nAPI documentation can be found at [rubydoc.info](http://rubydoc.info/github/jimmycuadra/to_lang/master/frames).\n\n## Feedback and Contributions\n\nFeedback is greatly appreciated. If you have any problems with **to_lang**, please open a new issue. Make sure you are using the latest version of the gem, or HEAD if you've cloned the Git repository directly. Please include debugging output from using the `:debug` option of `translate`, if relevant to your issue. If you'd like to fix bugs, add features, or improve the library in general, feel free to fork the project and send me a pull request with your changes.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjimmycuadra%2Fto_lang","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjimmycuadra%2Fto_lang","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjimmycuadra%2Fto_lang/lists"}