Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[i18n] Translatable Casper default theme #306

Closed
wants to merge 8 commits into from

Conversation

juan-g
Copy link

@juan-g juan-g commented May 2, 2017

[i18n] Translatable Casper default theme

no issue

  • (note: this Casper commit completes a Ghost commit with full translation of Ghost's frontend for site visitors: "[i18n] Translatable Ghost's frontend: Themes, dates, pagination, subscribe forms")

  • all 21 theme text strings included in translatable {{t}} handlebars helpers in Casper, the Ghost default theme which is the model for all Ghost themes

  • easily readable original English text in templates, for very simple translation

  • usage examples, in .hbs templates:

  {{t "mytheme" "Get the latest posts delivered right to your inbox"}}
  {{{t "mytheme" "Proudly published with {ghostLink}" ghostLink="<a href=\"https://ghost.org\">Ghost</a>"}}}
  • and in .json translation files, for example for Spanish:
  "mytheme": {
      "Get the latest posts delivered right to your inbox": "Recibe los últimos artículos directamente en tu buzón",
      "Proudly published with {ghostLink}": "Publicado con {ghostLink}"
  }
  • also added two very small stylesheet files, assets/css/en.css and assets/css/es.css, for some css content strings that needed translation by override; stylesheets linked using Ghost's standard getAssetUrl
  • see the complementary Ghost commit for additional details

@juan-g
Copy link
Author

juan-g commented May 2, 2017

The complementary Ghost pull request is:

[i18n] Translatable Ghost's frontend: Themes, dates, pagination, subscribe forms
TryGhost/Ghost#8437

@ErisDS ErisDS self-assigned this May 3, 2017
@juan-g juan-g force-pushed the i18n-translatable-frontend branch 2 times, most recently from abf0a4b to b9f2b3e Compare May 7, 2017 14:25
no issue

- (note: this Casper commit completes a Ghost commit with full translation of Ghost's frontend for site visitors: "[i18n] Translatable Ghost's frontend: Themes, dates, pagination, subscribe forms")

- all 21 theme text strings included in translatable {{t}} handlebars helpers in Casper, the Ghost default theme which is the model for all Ghost themes
- easily readable original English text in templates, for very simple translation
- usage examples, in .hbs templates:
  {{t "mytheme" "Get the latest posts delivered right to your inbox"}}
  {{{t "mytheme" "Proudly published with {ghostLink}" ghostLink="<a href=\"https://ghost.org\">Ghost</a>"}}}
- and in .json translation files, for example for Spanish:
  "mytheme": {
      "Get the latest posts delivered right to your inbox": "Recibe los últimos artículos directamente en tu buzón",
      "Proudly published with {ghostLink}": "Publicado con {ghostLink}"
  }
- also added two very small stylesheet files, assets/css/en.css and assets/css/es.css, for some css content strings that needed translation by override; stylesheets linked using Ghost's standard getAssetUrl
- see the complementary Ghost commit for additional details
@juan-g juan-g force-pushed the i18n-translatable-frontend branch from b9f2b3e to 215eb4f Compare May 7, 2017 17:22
pull request TryGhost#306

- renamed new {{i18nCss}} css translation helper as more user friendly
{{t_css}} for ease of use and consistency with the rest of helper names
- there is a complementary commit for Ghost's PR TryGhost/Ghost#8437
@juan-g
Copy link
Author

juan-g commented May 9, 2017

Added a minor commit to this pull request:

[i18n] Renamed new {{i18nCss}} css translation helper as {{t_css}}

pull request #306

pull request TryGhost#306

- for .hbs templates in content/themes, using translation files:
content/themes/mytheme/assets/translations/mytheme_en.json,
mytheme_es.json, mytheme_en-US.json, etc. (replacing "mytheme" with the
active theme, such as casper, etc.)
- more details in a complementary commit for Ghost's PR
TryGhost/Ghost#8437
@juan-g
Copy link
Author

juan-g commented May 18, 2017

[i18n] Separate .json translation files for themes

pull request #306

pull request TryGhost#306

- to facilitate translators' work, moved .css translation files for
themes from assets/css/en.css, etc. to
assets/translations/mytheme_en.css, etc. (replacing "mytheme" with the
active theme, such as casper, etc.)
- adjusted {{t_css}} helper and its test accordingly
- there is a complementary commit for Ghost's PR TryGhost/Ghost#8437
@juan-g
Copy link
Author

juan-g commented May 19, 2017

[i18n] Moved .css translation files for themes

pull request #306

…er helpers

pull request TryGhost#306

- using (t) translation helper's subexpressions inside {{plural}},
{{subscribe_form}}, and {{input_email}} helpers for placeholders, etc.,
instead of "where" parameters
- simplified these helpers; now similar to before the pull requests;
just a few objects needed conversion to string for {{plural}}
- since {{t}} translation helper returns new SafeString, there is no
need for {{{t}}} to preserve HTML; using now {{t}} instead in all cases
- adapted several templates for these changes
- subexpressions requested in pull request review
- there is a complementary commit for Ghost's PR TryGhost/Ghost#8437
@juan-g
Copy link
Author

juan-g commented May 27, 2017

[i18n] (t) translation helper's subexpressions for {{plural}} and other helpers

pull request #306

  • using (t) translation helper's subexpressions inside {{plural}}, {{subscribe_form}}, and {{input_email}} helpers for placeholders, etc., instead of "where" parameters
  • simplified these helpers; now similar to before the pull requests; just a few objects needed conversion to string for {{plural}}
  • since {{t}} translation helper returns new SafeString, there is no need for {{{t}}} to preserve HTML; using now {{t}} instead in all cases
  • adapted several templates for these changes
  • subexpressions requested in pull request review
  • there is a complementary commit for Ghost's PR [i18n] Translatable Ghost's frontend: Themes, dates, pagination, subscribe forms Ghost#8437

pull request TryGhost#306

- adapted theme template default.hbs for this change, including <html
lang="{{lang}}">
- see more details in the two complementary commits for Ghost's PR
TryGhost/Ghost#8437, and for gscan's PR TryGhost/gscan#48
juan-g added a commit to juan-g/gscan that referenced this pull request May 28, 2017
pull request TryGhost#48

- {{t_css}} helper removed, and {{theme}} and {{lang}} added to
knownHelpers
- see more details in the two complementary commits for Ghost's PR
TryGhost/Ghost#8437, and for Casper default theme's PR
TryGhost/Casper#306
@juan-g
Copy link
Author

juan-g commented May 28, 2017

[i18n] {{t_css}} helper replaced by {{theme}} and {{lang}}

pull request #306

kirrg001 pushed a commit to juan-g/Ghost that referenced this pull request Jan 9, 2018
pull request TryGhost#8437

- renamed new {{i18nCss}} css translation helper as more user friendly
{{t_css}} for ease of use and consistency with the rest of helper names
- there is a complementary commit for Casper default theme's PR
TryGhost/Casper#306
kirrg001 pushed a commit to juan-g/Ghost that referenced this pull request Jan 9, 2018
pull request TryGhost#8437

- for .hbs templates in content/themes, using translation files:
content/themes/mytheme/assets/translations/mytheme_en.json,
mytheme_es.json, mytheme_en-US.json, etc. (replacing "mytheme" with the
active theme, such as casper, etc.)
- during Ghost's initialization, first default internationalization just
for core briefly until settings for language and theme are available;
then full internationalization for core and theme
- files are read into memory just when needed
- included comments with next changes when language will be in settings
- there is a complementary commit for Casper default theme's PR
TryGhost/Casper#306
kirrg001 pushed a commit to juan-g/Ghost that referenced this pull request Jan 9, 2018
pull request TryGhost#8437

- to facilitate translators' work, moved .css translation files for
themes from assets/css/en.css, etc. to
assets/translations/mytheme_en.css, etc. (replacing "mytheme" with the
active theme, such as casper, etc.)
- adjusted {{t_css}} helper and its test accordingly
- there is a complementary commit for Casper default theme's PR
TryGhost/Casper#306
kirrg001 pushed a commit to juan-g/Ghost that referenced this pull request Jan 9, 2018
…er helpers

pull request TryGhost#8437

- using (t) translation helper's subexpressions inside {{plural}},
{{subscribe_form}}, and {{input_email}} helpers for placeholders, etc.,
instead of "where" parameters
- simplified these helpers; now similar to before the pull requests;
just a few objects needed conversion to string for {{plural}}
- since {{t}} translation helper returns new SafeString, there is no
need for {{{t}}} to preserve HTML; using now {{t}} instead in all cases
- adapted several templates for these changes
- subexpressions requested in pull request review
- there is a complementary commit for Casper default theme's PR
TryGhost/Casper#306
kirrg001 pushed a commit to juan-g/Ghost that referenced this pull request Jan 9, 2018
pull request TryGhost#8437

- {{t_css}} helper removed, and replaced by useful new helpers {{theme}}
and {{lang}}
- translation of optional CSS content text visible to site visitors,
such as "Read This Next", is done using the new helpers; therefore
frontend translation is still complete
- for themes with CSS content text, to translate it the following line
can be added after the style sheets to be overridden, usually on the
default.hbs theme template:
<link rel="stylesheet" type="text/css" href="{{asset
"translations/{theme}_{lang}.css" theme=(theme) lang=(lang)}}" />
- usage example for {{lang}}, which gives the current language tag:
<html lang="{{lang}}">
- examples of language tags from RFC 5646: de (German), fr (French), ja
(Japanese), en-US (English as used in the United States)
- standard: "Language tags in HTML and XML"
https://www.w3.org/International/articles/language-tags/
- {{theme}} gives the simplified name of the active theme, as used in
file names, etc.
- added functionality to {{asset}} helper, allowing optional
replacements to build URLs
- Handlebars subexpressions such as (theme) and (lang) can be used in
parameters, e.g.:
{{asset "translations/{theme}_{lang}.css" theme=(theme) lang=(lang)}}
which can be equivalent to: {{asset "translations/mytheme_en-US.css"}}
- added tests for the two new helpers
- removal of {{t_css}} requested in pull request review
- there are two complementary commits for Casper default theme's PR
TryGhost/Casper#306, and for gscan's PR TryGhost/gscan#48
kirrg001 pushed a commit to juan-g/Ghost that referenced this pull request Jan 9, 2018
pull request TryGhost#8437

- facilitating more the use of placeholders with subexpressions in full
translation strings, rather than translating separate sentence
fragments; often those fragments are in different order for different
languages, therefore placeholders are better and more flexible
- when preserving HTML, back to using {{{t}}}; from now, this helper
doesn't use a SafeString object which would prevent escaping, because
often other helpers need that (t) returns a string to be able to work as
subexpression
- because of this, the {{plural}} helper is again like before these pull
requests, but with translations working
- examples:
{{tags prefix=(t "casper" " on ")}}
{{{t "casper" "Read <a href='{url}'>more posts</a> by this author"
url=(url)}}}
- there is a complementary commit for Casper default theme's PR
TryGhost/Casper#306
kirrg001 pushed a commit to juan-g/Ghost that referenced this pull request Jan 9, 2018
pull request TryGhost#8437

- {{t}} translation helper, simplified as much as possible to facilitate
and speed up the work of theme designers and users customizing Ghost
themes
- now there is no need to include the theme name in {{t}}
- before:
    {{t "mytheme" "Subscribe"}}
- after:
    {{t "Subscribe"}}
- this modifies just the {{t}} format; everything else works as before
- this improvement is for .hbs theme templates, e.g.:
{{t "Get the latest posts delivered right to your inbox"}}
- the few sentences in .hbs core frontend templates need a `where`
parameter, not needed for themes:
{{t "You've successfully subscribed to" where="frontend"}}
- change compatible with parameters for replacement placeholders
- probably, developers of future apps with templates will also use this
parameter, e.g. `where="myapp"` (there will likely be one theme and
several apps enabled at the same time).
- (t) nested translation helpers are simplified in the same way:
- before:
    {{tags prefix=(t "mytheme" " on ")}}
- after:
    {{tags prefix=(t " on ")}}
- a complex example with multiple (t) nested translation helpers is the
{{plural}} helper
- before:
    {{plural ../pagination.total empty=(t "mytheme" "No posts")
singular=(t "mytheme" "1 post") plural=(t "mytheme" "% posts")}}
- after:
    {{plural ../pagination.total empty=(t "No posts") singular=(t "1
post") plural=(t "% posts")}}
- as an additional benefit, when creating new themes by modifying
others, there is no need to change the theme name in each translation
helper
- {{t}} test updated
- content/translations/README.md updated
- there is a complementary commit for Casper default theme's PR
TryGhost/Casper#306
@HLFH
Copy link

HLFH commented Jan 22, 2018

Hi. Will this be merged (are there some showstoppers) or shall we switch to https://github.com/juan-g/WorldCasper2?

@kirrg001
Copy link
Contributor

Hi. Will this be merged (are there some showstoppers)

Won't be merged. Forgot to close.

or shall we switch to https://github.com/juan-g/WorldCasper2?

👍

@kirrg001 kirrg001 closed this Jan 22, 2018
@HLFH
Copy link

HLFH commented Jan 22, 2018

Thank you @juan-g and @kirrg001 for this great work!
I added a PR for Isso support, French translation and Feedly fix on juan-g/WorldCasper2#2.
Have a great evening!

@guillaume-sainthillier
Copy link

This work is awesome.
Could you explain me the reasons why this PR is not merged ?
I would be happy to make you a PR for at least call the "t" helper in the templates even if the translation files are not hosted directly in this repo.

@fr0der1c
Copy link

fr0der1c commented Apr 3, 2019

I wonder why this PR is not merged too. Translation is a built-in ability for Ghost, but the default theme doesn't support it. Wow.

@kevinansfield
Copy link
Member

kevinansfield commented Apr 3, 2019

As mentioned in the comment above, if you want a translated theme you're free to use a fork such as https://github.com/juan-g/WorldCasper2 or any other theme and adapt it to your needs 😉 There is full documentation available for translating your theme here https://docs.ghost.org/api/handlebars-themes/helpers/translate/

Casper is intended as a minimal default theme that's useful for Ghost beginners to get started and customise to their needs. Adding localisation features which complicate/obscure the theme development for the large majority of users which don't have any localisation needs is counter to that focus.

@fr0der1c
Copy link

fr0der1c commented Apr 4, 2019

@kevinansfield

Adding localisation features which complicate/obscure the theme development

Will it complicate much? I thought not hard-coding is a good thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants