Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/calebhearth/title
I18n your <title>s
https://github.com/calebhearth/title
Last synced: 5 days ago
JSON representation
I18n your <title>s
- Host: GitHub
- URL: https://github.com/calebhearth/title
- Owner: calebhearth
- License: mit
- Created: 2013-07-10T17:54:28.000Z (over 11 years ago)
- Default Branch: main
- Last Pushed: 2024-05-21T22:19:39.000Z (7 months ago)
- Last Synced: 2024-12-16T02:03:31.031Z (12 days ago)
- Language: Ruby
- Homepage: https://www.calebhearth.com/store-page-titles-in-i18n
- Size: 31.3 KB
- Stars: 199
- Watchers: 4
- Forks: 13
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Title
Translations for \s!
## Usage
Add to your translations:
```yaml
en:
titles:
# titles.application defaults to the sigficant portion of
# AppName::Application, which would be:
application: AppName
dashboards:
show: Dashboard
users:
show: '%{user}'
new: Registration
```And to your HTML:
```erb
<%= title %>
```And to your `User` model:
```ruby
def to_s
name
end
```You can pass additional values to the `#title` helper, which can be referenced
in your translations:```erb
<%= title(user_name: current_user.name) %>
``````yaml
en:
titles:
application: '%{user_name} - AppName'
```## Acknowledgement
Though the idea of translating titles was arrived at seperately, [Brandon
Keepers] wrote [Abusing Rails I18N to Set Page Titles] which outlines an
extremely similar approach, and from whence came the idea of using the view
context to get local assigns to be used in interpolation.[Brandon Keepers]: https://github.com/bkeepers
[Abusing Rails I18N to Set Page Titles]: https://opensoul.org/2012/11/05/abusing-rails-i18n-to-set-page-titles/