diff options
author | Ezekiel Kigbo <ekigbo@gitlab.com> | 2019-06-25 02:37:44 +0000 |
---|---|---|
committer | Ezekiel Kigbo <ekigbo@gitlab.com> | 2019-06-27 12:12:32 +1000 |
commit | 6eaf0cb78d37e06852a1674d1099638f7d144a7a (patch) | |
tree | b03ea90447156c608ffde6c1088247e53e4b8c00 | |
parent | a08b42c2a6d067f2d17a138508e6c2d1adbd282b (diff) | |
download | gitlab-ce-6eaf0cb78d37e06852a1674d1099638f7d144a7a.tar.gz |
Update info on externalizing links
Added example for splitting strings with links
in javascript and sentence to interpolation.
-rw-r--r-- | doc/development/i18n/externalization.md | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/doc/development/i18n/externalization.md b/doc/development/i18n/externalization.md index ce310672dad..5b21bec38cf 100644 --- a/doc/development/i18n/externalization.md +++ b/doc/development/i18n/externalization.md @@ -135,7 +135,7 @@ There is also and alternative method to [translate messages from validation erro ### Interpolation Placeholders in translated text should match the code style of the respective source file. -For example use `%{created_at}` in Ruby but `%{createdAt}` in JavaScript. +For example use `%{created_at}` in Ruby but `%{createdAt}` in JavaScript. Make sure to [avoid splitting sentences when adding links](#avoid-splitting-sentences-when-adding-links). - In Ruby/HAML: @@ -267,20 +267,33 @@ should be externalized as follows: This also applies when using links in between translated sentences, otherwise these texts are not translatable in certain languages. -Instead of: - -```haml -- zones_link = link_to(s_('ClusterIntegration|zones'), 'https://cloud.google.com/compute/docs/regions-zones/regions-zones', target: '_blank', rel: 'noopener noreferrer') -= s_('ClusterIntegration|Learn more about %{zones_link}').html_safe % { zones_link: zones_link } -``` +- In Ruby/HAML + + Instead of: + + ```haml + - zones_link = link_to(s_('ClusterIntegration|zones'), 'https://cloud.google.com/compute/docs/regions-zones/regions-zones', target: '_blank', rel: 'noopener noreferrer') + = s_('ClusterIntegration|Learn more about %{zones_link}').html_safe % { zones_link: zones_link } + ``` + + Set the link starting and ending HTML fragments as variables like so: + + ```haml + - zones_link_url = 'https://cloud.google.com/compute/docs/regions-zones/regions-zones' + - zones_link_start = '<a href="%{url}" target="_blank" rel="noopener noreferrer">'.html_safe % { url: zones_link_url } + = s_('ClusterIntegration|Learn more about %{zones_link_start}zones%{zones_link_end}').html_safe % { zones_link_start: zones_link_start, zones_link_end: '</a>'.html_safe } + ``` -Set the link starting and ending HTML fragments as variables like so: +- In javascript + ```js + {{ + sprintf(s__("ClusterIntegration|Learn more about %{zones_link_start}zones%{zones_link_end}"), { + linkStart: '<a href="https://cloud.google.com/compute/docs/regions-zones/regions-zones" target="_blank" rel="noopener noreferrer">' + linkEnd: '</a>', + }) + }} -```haml -- zones_link_url = 'https://cloud.google.com/compute/docs/regions-zones/regions-zones' -- zones_link_start = '<a href="%{url}" target="_blank" rel="noopener noreferrer">'.html_safe % { url: zones_link_url } -= s_('ClusterIntegration|Learn more about %{zones_link_start}zones%{zones_link_end}').html_safe % { zones_link_start: zones_link_start, zones_link_end: '</a>'.html_safe } -``` + ``` The reasoning behind this is that in some languages words change depending on context. For example in Japanese は is added to the subject of a sentence and を to the object. This is impossible to translate correctly if we extract individual words from the sentence. |