{"id":16944941,"url":"https://github.com/mattetti/merb_babel","last_synced_at":"2025-07-03T20:32:48.326Z","repository":{"id":399075,"uuid":"17269","full_name":"mattetti/merb_babel","owner":"mattetti","description":"Merb Babel is a dead simple translation/localization tool for Merb","archived":false,"fork":false,"pushed_at":"2009-01-16T23:17:55.000Z","size":124,"stargazers_count":19,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-21T10:47:56.117Z","etag":null,"topics":[],"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/mattetti.png","metadata":{"files":{"readme":"README.markdown","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}},"created_at":"2008-05-16T05:12:10.000Z","updated_at":"2021-10-31T10:15:42.000Z","dependencies_parsed_at":"2022-07-07T15:11:24.319Z","dependency_job_id":null,"html_url":"https://github.com/mattetti/merb_babel","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mattetti/merb_babel","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattetti%2Fmerb_babel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattetti%2Fmerb_babel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattetti%2Fmerb_babel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattetti%2Fmerb_babel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mattetti","download_url":"https://codeload.github.com/mattetti/merb_babel/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattetti%2Fmerb_babel/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261265710,"owners_count":23132677,"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-13T21:19:27.030Z","updated_at":"2025-07-03T20:32:48.299Z","avatar_url":"https://github.com/mattetti.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"Merb_babel\n=========\n\nA plugin for the Merb framework that provides locales, languages, countries. (in a thread safe environment)\n\n\nPurpose of Merb\\_babel\n---------------------\n\nMerb_babel is primarily written to fulfill my personal needs. Instead of porting my http://github.com/mattetti/globalite plugin over, I decided to re write it from scratch learning from my mistakes.\n\nGoals:\n\n* simplicity\n* speed\n\nMy first and simple objective is to get Merb to work in Simplified and Traditional Chinese + switch from one to the other.\n\nAlso, as of today, I'm not planning on supporting model localization since I believe it's easy to do, and in most cases it's too specific to use a plugin. (but other plugins offer that for you anyway ;) )\n\nOne of the objectives is that people can add Merb\\_babel to their project and use merb in a different language without worrying about internationalization/localization. I hope to keep merb helpers and other plugins (merb\\_activerecord / merb\\_datamapper / merb\\_sequel) localized so someone can define his app's locale/language/country and Merb will talk his language right away.\n\nBefore you go further, you might want to read [this explanation about i18n/l10n](http://www.w3.org/International/questions/qa-i18n)\n\nUsage\n------\n\nIn your application controller add:\n\n    before :set_locale\n    \n\nand access the user locale using  @controller.locale (or simply #locale in the controller)\nIf a locale is set, you can also access @controller.language and @controller.country (same thing, you can use #language or #country from within your controller scope)\n\nThe locale is stored in request.env[:locale]\n\nAt the moment you have 3 ways of setting up a locale:\n\n* default way in the config settings (that you can overwrite in your init.rb file )\n\n    Merb::Plugins.config[:Merb_babel] = {\n      :default_locale =\u003e 'en-US',\n      :default_language =\u003e 'en',\n      :default_country =\u003e 'US'\n    }\n    \n* per request basis, by sending a param called locale (language, and country will set their own values)\n* store the locale in the session\n* use routes\n\nBabel doesn't support http header lookup yet.\n\nSet locale in your routes\n--------------------------\n\n    r.match(/\\/?(en\\-US|en\\-UK|es\\-ES|es\\-AR)?/).to(:locale =\u003e \"[1]\") do |l|\n      l.match(\"/articles/:action/:id\").to(:controller =\u003e \"articles\")\n    end\n    \nWhat if you don't need to use a full locale?\n--------------------------------------------\n\nsome people might not need to use the full locale, they just want to use one version of a language and the locale is an overkill. Don't worry, you can use the language instance variable.\n\n    before :set_language\n    \n    \nAll locale work is done in ``merb_babel/lib/merb_babel/m_locale.rb`` and tested in ``spec/merb_babel_spec.rb``\n\nLocalization(L10n)\n------------------\n\nL10n is basically the adaptation of your product to a specific locale. In our case, we see L10n as the storing and retrieval of localized data. (for a locale or language)\n\nLocalizations are loaded from localization files.\n\nLocalization files are simple yaml files that get loaded in memory. By default Merb\\_babel will look in ./lang for localization files. The default location is defined in Merb::Plugins.config[:merb_babel][:localization_dirs] and can be overwritten. Also, you can add more folders to look for by calling:\n\n    add_localization_dir(path_with_more_localization_files)\n    \nNote: when you add a new localization directory, localizations gets reloaded.\nThis needs to be done when Merb loads as I didn't add a mutex around that task yet.\n\nLocalizations are available in #localizations and are namespaced as follows:\n\n    localizations['en'][:right] =\u003e 'right'\n    localizations['en'][:left] =\u003e 'left'\n    localizations['en']['US'][:greeting] =\u003e 'Howdie'\n    localizations['en']['AU'][:greeting] =\u003e \"Good'ay\"\n    \nFor that the localization files to be loaded properly, you need to follow some conventions:\n\n* you have to declare a merb localization language code pair: \n    mloc\\_language_code: en\nwhere en represents the language code of the localization\n\n* All generic localization for a language should go under their own language file. Region/culture specific localizations have to go to their own files and will be used if the full locale is set.\n\n* A localization file is recognized as being locale specific if the mloc_country_code pair is set.\n\n* ONLY localizations/translations specific to a locale should be written in a locale file.\n\n* Recommended: set the mloc\\_language_name pair so you list the available languages in their own language.\n\n* look at examples in spec/lang\n\nAll the Localization(L10n) work is done in ``merb_babel/lib/merb_abel/m_l10n.rb`` and tested in ``spec/m_l10n_spec.rb``\n\n\nInternationalization(I18n)\n--------------------------\n\nI18n enables easy localization of your product. That's what the developer/designer user to make their data localizable.\n\nAt the moment, only strings can be localized/translated.\n\nIn your controller, or view simply do:\n\n    translate(:localization_key)\n\nYou might prefer a shorter version so here are some aliases for you to use:\n\n    babelize(:translation_key)\nor\n    t(:translation_key)  \nor\n    _(:translation_key)\n    \nThe translation will use the full locale (language and country) if set and available, otherwise the language translation will be displayed.\n\n*Params*\n\nYou can pass a hash of parameters after the translation key. For instance:\n\n    t(:greetings, :language =\u003e 'fr')\n\nWould lookup the French translation for the greetings key and return 'Salut'\n\nYou can also pass the country code to use the full locale.\n\n    t(:greetings, :language =\u003e 'en', :country =\u003e 'AU')\n    \nwould lookup the Australian English translation for the greetings key and return \"G'day\"\n\n\nOther plugins you might want to look at:\n----------------------------------------\n\n* http://github.com/myabc/merb_global\n* http://github.com/lemon/poppycock","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattetti%2Fmerb_babel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmattetti%2Fmerb_babel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattetti%2Fmerb_babel/lists"}