{"id":22831544,"url":"https://github.com/phrase/slimkeyfy","last_synced_at":"2025-04-23T19:43:24.050Z","repository":{"id":18617540,"uuid":"21823165","full_name":"phrase/slimkeyfy","owner":"phrase","description":"Extract plain Strings from .slim views and rails controllers to replace them with I18n's t() method","archived":false,"fork":false,"pushed_at":"2024-02-20T08:34:28.000Z","size":460,"stargazers_count":59,"open_issues_count":2,"forks_count":9,"subscribers_count":21,"default_branch":"master","last_synced_at":"2025-03-30T02:51:08.823Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://phrase.com","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/phrase.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":"2014-07-14T14:44:54.000Z","updated_at":"2024-11-12T20:23:16.000Z","dependencies_parsed_at":"2024-12-12T20:33:50.566Z","dependency_job_id":"73782c2f-17c1-4dd1-ab79-ff38bf7471ea","html_url":"https://github.com/phrase/slimkeyfy","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/phrase%2Fslimkeyfy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phrase%2Fslimkeyfy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phrase%2Fslimkeyfy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phrase%2Fslimkeyfy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phrase","download_url":"https://codeload.github.com/phrase/slimkeyfy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250501386,"owners_count":21441013,"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-12-12T20:26:32.771Z","updated_at":"2025-04-23T19:43:23.995Z","avatar_url":"https://github.com/phrase.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"Slimkeyfy\n=\nExtract plain Strings from .slim views and Rails controllers to replace them with I18n's t() method.\nKeys with it's translations will be streamed to a YAML file.\nNon english keys get translated with deepl translator gem ( you need to get your api first ).\n\nRead more in this blog post: [Phrase Blog: Make your Rails App localizable with Slimkeyfy](https://phrase.com/blog/posts/slim-localize-your-slim-templates-in-a-second-with-slimkeyfy/)\n\n```ruby\nslimkeyfy app/views/users/show.html.slim en\n# users/show.html.slim\nh1 Hello World!\n# converts to\nh1= t('.hello_world')\n# config/locales/users.en.yaml\n# en:\n#   user:\n#     show:\n#       hello_world: Hello World!\n```\n\nInstall\n-\n\nWith Ruby Gems\n```ruby\n\u003e gem install slimkeyfy\n```\n\nWith Bundler\n```ruby\ngroup :development do\n  # Github\n  # gem 'slimkeyfy', github: 'phrase/slimkeyfy'\n  # or with concrete version\n  gem 'slimkeyfy', '~\u003e 0.1'\nend\n```\n\nApproach\n-\nMost of the time tools like this go for a 80/20 approach stating that 80% can be done right and 20% have to be done manually. Our approach is similar but a bit different. Translating and tagging your Rails app can be error prone. In order to reduce this Slimkeyfy streams in every line that matches the regular expression engine and prompts you to take an action. This guarantees a higher quality but also gets us closer to the 90%. It might take a little more time than full automation. The collected data is then processed into a YAML file. If you don't provide a YAML one will be created. All your processed views and resulting translations will be merged with the existing YAML.\n\nUsage\n-\n```unix\nslimkeyfy INPUT_FILENAME_OR_DIRECTORY LOCALE (e.g. en, fr) [YAML_FILE] [Options]\n```\n- If you do not provide a YAML file - one will be created at configs/locales/view_folder_name.locale.yml\n- If you provide one make sure that the top level locale matches your provided locale\n- The YAML file will be loaded as a hash and deep_merged with the new found translations\n\nI18n for keys addition\n----------------------\n( from alekseyl translator branch: https://github.com/alekseyl/slimkeyfy/tree/translator )\nI18n keys better be in english so if you start I18n from other than en locale you cannot use original slikeyfy approach, you need to translate keys first\nTwo options added to CLI:\n```unix\n  '-t', '--translator-api-key [API_KEY]', 'API key for DeepL'\n  '-l', '--keys-from-locale LOCALE', 'translate keys from locale'\n```\n\nAPI key can be given directly in CLI or added with export:\n\n```unix\n   export DEEPL_AUTH_KEY=\"DEEPL_AUTH_KEY_KEY\"\n```\n\nHow to get one:\nGo to https://www.deepl.com\nGet an account, check out the free API access (pro version will require Gem changes first - API endpoint for free version is hard coded)\n\n\n**Stream** - walks through the given file/files and if a regex hits you will be prompted to apply (y)es, discard (n)o, tag (x) (comments suggestions above the processed line) or (a)bort (only aborts the current file).\n\nwithout YAML file\n```unix\nslimkeyfy path/to/your/file.html.slim en\n```\nwith given YAML file (has to be valid YAML! with the top level locale matching your provided locale)\n```unix\nslimkeyfy path/to/your/dir/ en path/to/your/en.yml\n```\nA Backup (.bak) of the old file will be created e.g. index.html.slim =\u003e index.html.slim.bak.\nProviding ---no-backup creates the backups temporarily and deletes them right after you apply your changes. (be careful!)\n\nExample Usage\n-\n```unix\nyour_app_name/\n  |- app/\n    |- views/\n      |- user/\n        new.html.slim\n        show.html.slim\n      |- project/\n        index.html.slim\n        ...\n    ...\n  |- config/\n    |- locales/\n      en.yml\n      ...\n  ...\n\n\u003e pwd\n../your_app_name/\n\n\u003e slimkeyfy app/views/users/ en\n... choose your changes here (y/n/x/a)\n\n\u003e ls app/views/users/\n    new.html.slim\n    show.html.slim\n    new.html.slim.bak\n    show.html.slim.bak\n\n\u003e ls config/locales/\n    user.en.yml\n    en.yml\n\n\u003e cat ../users/new.html.slim.bak\n  h1 Hello World!\n\n\u003e cat ../users/new.html.slim\n  h1= t('.hello_world')\n\n\u003e cat config/locales/en.yml\n  --\n  en:\n    keys..\n\n\u003e cat config/locales/users.en.yml\n  ---\n  en:\n    users:\n      new:\n        hello_world: Hello World!\n      show:\n        ...\n```\nSuggested Workflow\n-\nAs HTML is not 100% parsable there will be errors in the conversion. To minimize your error rate we suggest to approach each view or view_folder individually. The i18n-tasks gem helped a lot by finding errors. Always double check your views and make sure that everything went smoothly. Especially double check all your links. Here is an example workflow:\n```ruby\n# 1. create a branch for a view folder\n\u003e git checkout -b users_localization\n\n# 2. slimkeyfy the view folder you would like to tag\n\u003e slimkeyfy app/views/users/ en\n\n# 3. go through all files and verify/add missing translations\n# (check against the .bak files (use git diff))\n\u003e git diff app/views/users/views.html.slim\n\n# 4. add your translations + keys to your locale file(s)\n# 4.1 optional: Use the I18n-tasks gem to find missing translations\n\n# 5. go through all your views and click through everything to actually \"see\" what changed\n\n# 6. If everything is fine - clean up (remove .baks)\n\u003e rm app/views/users/*.bak\n# Optional: remove temporary YAML files\n\u003e rm config/locales/users.en.yml\n```\nTesting\n-\nTo test the application simply call rspec spec/.. from the root directory of slimkeyfy\n```unix\nbundle install\nbundle exec rspec spec/\n```\nPhrase Integration\n-\nNow that you processed your views and moved the generated keys to your localization files it is quite easy to push it to Phrase. If you have not set up your account yet [take a look here](https://phrase.com/). You can use the [Phrase Client](https://github.com/phrase/phraseapp-client) to easily push your translations to Phrase.\n\nTodo\n-\n- a dry run option where you can see what will happen if you convert.\n- currently you are prompted for all hits - We would like to do 70-80% automatically and prompt for the 20-30% that cannot be decided upon.\n- adding / generalizing Regular Expressions for better hit rate\n\nClosed Todos\n-\n- YAML placeholders are supported - thx@joshblour\n\nIssues\n-\n- If you choose to take a lot of files at one time make sure to go through with it. It is not an issue to completely rerun everything (already translated strings are ignored) but should be avoided.\n- some hits will not be correct, some things that should be found are not and sometimes the regex engine won't work for mysterious reasons. Slimkeyfy is a helper, it does not provide full automation. It might make your work a little easier.\n\nReferences\n-\n* Other tools, not slim specific for this task is the [i15r gem](https://github.com/balinterdi/i15r). It can process .haml and .erb.\n* I strongly recommend checking your translated app with the [i18n-tasks gem](https://github.com/glebm/i18n-tasks). It is a great tool in     finding missing and unused translations.\n* Always consult the [Official Rails Internationalization guide](http://guides.rubyonrails.org/i18n.html) if in doubt.\n* Visit [Phrase on Github](https://github.com/phrase)\n\n## Get help / support\n\nPlease contact [support@phrase.com](mailto:support@phrase.com?subject=[GitHub]%20) and we can take more direct action toward finding a solution.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphrase%2Fslimkeyfy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphrase%2Fslimkeyfy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphrase%2Fslimkeyfy/lists"}