Skip to content

Commit

Permalink
Add translate="no" tags throughout the project
Browse files Browse the repository at this point in the history
We skip translation only on names of modules, types,
functions, and code snippets. For example, the
subsection inside a module page are still translated.
The rationale is that terms like "function" and "macro"
appear as is in the text, without code tags, therefore
they are translated, so they same should apply to
subsections headers.
  • Loading branch information
josevalim committed Nov 21, 2021
1 parent f49e099 commit add7a0d
Show file tree
Hide file tree
Showing 20 changed files with 110 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
{{#each suggestions}}
<a href="{{link}}" class="autocomplete-suggestion" data-index="{{@index}}" tabindex="-1">
<div class="title">
{{{title}}}
<span translate="no">{{{title}}}</span>
{{#if label}}
<span class="label">({{label}})</span>
{{/if}}
</div>

{{#if description}}
<div class="description">
<div class="description" translate="no">
{{{description}}}
</div>
{{/if}}
Expand Down
4 changes: 3 additions & 1 deletion assets/js/handlebars/templates/search-results.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
{{#each results}}
<div class="result">
<h2 class="result-id">
<a href="{{this.ref}}">{{this.title}} <small>({{this.type}})</small></a>
<a href="{{this.ref}}">
<span translate="no">{{this.title}}</span> <small>({{this.type}})</small>
</a>
</h2>
{{#each excerpts}}
<p class="result-elem">{{{this}}}</p>
Expand Down
10 changes: 6 additions & 4 deletions assets/js/handlebars/templates/sidebar-items.handlebars
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
{{#each nodes as |node nodeId|}}
{{#groupChanged ../this node.group}}
<li class="group">{{node.group}}</li>
<li class="group" {{#isArray node.headers}}{{else}}translate="no"{{/isArray}}>
{{node.group}}
</li>
{{/groupChanged}}

{{#nestingChanged ../this node}}
<li class="nesting-context" aria-hidden="true">{{node.nested_context}}</li>
<li class="nesting-context" aria-hidden="true" translate="no">{{node.nested_context}}</li>
{{/nestingChanged}}

<li class="{{#isLocal node.id}}current-page open{{/isLocal}} {{#if node.nested_title}}nested{{/if}}">
{{! When visiting a module page, the link to this module page
in the menu should not link to a new page, instead should link
to the top of the page itself. }}
<a href="{{node.id}}.html" class="expand">
<a href="{{node.id}}.html" class="expand" {{#isArray node.headers}}{{else}}translate="no"{{/isArray}}>
{{#if node.nested_title}}
{{{node.nested_title}}}
{{else}}
Expand Down Expand Up @@ -62,7 +64,7 @@
<ul class="{{group.key}}-list deflist">
{{#each group.nodes}}
<li>
<a href="{{node.id}}.html#{{anchor}}">{{id}}</a>
<a href="{{node.id}}.html#{{anchor}}" translate="no">{{id}}</a>
</li>
{{/each}}
</ul>
Expand Down
4 changes: 2 additions & 2 deletions assets/js/handlebars/templates/tooltip-body.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
{{else}}
<div class="detail-header">
<h1 class="signature">
{{this.hint.title}}
<div class="version-info">{{this.hint.version}}</div>
<span translate="no">{{this.hint.title}}</span>
<div class="version-info" translate="no">{{this.hint.version}}</div>
</h1>
</div>
{{#if this.hint.description}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<form autocomplete="off">
<select class="sidebar-projectVersionsDropdown" dir="rtl">
{{#each nodes}}
<option value="{{url}}"{{#if isCurrentVersion}} selected disabled{{/if}}>
<option translate="no" value="{{url}}"{{#if isCurrentVersion}} selected disabled{{/if}}>
{{version}}
</option>
{{/each}}
Expand Down
2 changes: 2 additions & 0 deletions formatters/html/dist/app-a404e1e870b77c874f9e.js

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions formatters/html/dist/app-b80d21cdb7d74c374d29.js

This file was deleted.

2 changes: 1 addition & 1 deletion lib/ex_doc/formatter/epub/templates/module_template.eex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%= head_template(config, %{title: module.title}) %>
<h1 id="content">
<%= H.module_title(module) %>
<%= module.title %> <%= H.module_type(module) %>
</h1>

<%= if deprecated = module.deprecated do %>
Expand Down
12 changes: 3 additions & 9 deletions lib/ex_doc/formatter/html/templates.ex
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,9 @@ defmodule ExDoc.Formatter.HTML.Templates do
@doc """
Returns the HTML formatted title for the module page.
"""
def module_title(%{type: :task, title: title}),
do: title

def module_title(%{type: :module, title: title}),
do: title

def module_title(%{type: type, title: title}),
do: title <> " <small>#{type}</small>"
def module_type(%{type: :task}), do: ""
def module_type(%{type: :module}), do: ""
def module_type(%{type: type}), do: "<small>#{type}</small>"

@doc """
Gets the first paragraph of the documentation of a node. It strips
Expand Down Expand Up @@ -277,7 +272,6 @@ defmodule ExDoc.Formatter.HTML.Templates do
search_template: [:config, :nodes_map],
sidebar_template: [:config, :nodes_map],
summary_template: [:name, :nodes],
summary_entry_template: [:node],
redirect_template: [:config, :redirect_to],
bottom_actions_template: [:refs]
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="summary-row">
<div class="summary-signature">
<a href="<%=enc module_node.id %>.html"><%=h module_node.title %></a>
<a href="<%=enc module_node.id %>.html" translate="no"><%=h module_node.title %></a>
<%= if deprecated = module_node.deprecated do %>
<span class="deprecated" title="<%= h(deprecated) %>">deprecated</span>
<% end %>
Expand Down
6 changes: 3 additions & 3 deletions lib/ex_doc/formatter/html/templates/detail_template.eex
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this <%= pretty_type(node) %></span>
</a>
<h1 class="signature"><%=h node.signature %></h1>
<h1 class="signature" translate="no"><%=h node.signature %></h1>
<%= if node.source_url do %>
<a href="<%= node.source_url %>" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
Expand All @@ -29,11 +29,11 @@
<h2>Specs</h2>
<div class="specs">
<%= for spec <- specs do %>
<pre><%= spec %></pre>
<pre translate="no"><%= spec %></pre>
<% end %>
</div>
<% end %>

<%= node.rendered_doc |> link_detail_headings(enc(node.id)) %>
<%= link_detail_headings(node.rendered_doc, enc(node.id)) %>
</section>
</section>
6 changes: 3 additions & 3 deletions lib/ex_doc/formatter/html/templates/footer_template.eex
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
<p>
<span class="line">
Built using
<a href="https://github.com/elixir-lang/ex_doc" title="ExDoc" target="_blank" rel="help noopener">ExDoc</a> (v<%= ExDoc.version() %>) for the
<a href="https://elixir-lang.org" title="Elixir" target="_blank">Elixir programming language</a>.
<a href="https://github.com/elixir-lang/ex_doc" title="ExDoc" target="_blank" rel="help noopener" translate="no">ExDoc</a> (v<%= ExDoc.version() %>) for the
<a href="https://elixir-lang.org" title="Elixir" target="_blank" translate="no">Elixir programming language</a>.
</span>
<span class="line">
Designed by
<a href="https://twitter.com/dignifiedquire" target="_blank" rel="noopener" title="@dignifiedquire">Friedel Ziegelmayer</a>.
<a href="https://twitter.com/dignifiedquire" target="_blank" rel="noopener" title="@dignifiedquire" translate="no">Friedel Ziegelmayer</a>.
</span>
</p>
<p>
Expand Down
103 changes: 52 additions & 51 deletions lib/ex_doc/formatter/html/templates/module_template.eex
Original file line number Diff line number Diff line change
@@ -1,56 +1,57 @@
<%= head_template(config, %{title: module.title, type: module.type}) %>
<%= sidebar_template(config, nodes_map) %>
<%= head_template(config, %{title: module.title, type: module.type}) %>
<%= sidebar_template(config, nodes_map) %>

<h1>
<%= module_title(module) %> <small class="app-vsn">(<%= config.project %> v<%= config.version %>)</small>
<%= if module.source_url do %>
<a href="<%= module.source_url %>" title="View Source" class="view-source" rel="help">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
<% end %>
<%= for annotation <- module.annotations do %>
<span class="note">(<%= annotation %>)</span>
<% end %>
</h1>
<h1>
<span translate="no"><%= module.title %></span> <%= module_type(module) %>
<small class="app-vsn" translate="no">(<%= config.project %> v<%= config.version %>)</small>
<%= if module.source_url do %>
<a href="<%= module.source_url %>" title="View Source" class="view-source" rel="help">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
<% end %>
<%= for annotation <- module.annotations do %>
<span class="note">(<%= annotation %>)</span>
<% end %>
</h1>

<%= if deprecated = module.deprecated do %>
<div class="deprecated">
This <%= module.type %> is deprecated. <%= h(deprecated) %>.
</div>
<% end %>
<%= if deprecated = module.deprecated do %>
<div class="deprecated">
This <%= module.type %> is deprecated. <%= h(deprecated) %>.
</div>
<% end %>

<%= if doc = module.rendered_doc do %>
<section id="moduledoc">
<%= link_moduledoc_headings(doc) %>
</section>
<% end %>
<%= if doc = module.rendered_doc do %>
<section id="moduledoc">
<%= link_moduledoc_headings(doc) %>
</section>
<% end %>

<%= if Enum.any?(summary, fn {_, v} -> v != [] end) do %>
<section id="summary" class="details-list">
<h1 class="section-heading">
<a class="hover-link" href="#summary">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this section</span>
</a>
Summary
</h1>
<%= for {name, nodes} <- summary, do: summary_template(name, nodes) %>
</section>
<% end %>
<%= if Enum.any?(summary, fn {_, v} -> v != [] end) do %>
<section id="summary" class="details-list">
<h1 class="section-heading">
<a class="hover-link" href="#summary">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this section</span>
</a>
Summary
</h1>
<%= for {name, nodes} <- summary, do: summary_template(name, nodes) %>
</section>
<% end %>

<%= for {name, nodes} <- summary, nodes != [], key = HTML.text_to_id(name) do %>
<section id="<%= key %>" class="details-list">
<h1 class="section-heading">
<a class="hover-link" href="#<%= key %>">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this section</span>
</a>
<%= name %>
</h1>
<div class="<%= key %>-list">
<%= for node <- nodes, do: detail_template(node, module) %>
</div>
</section>
<% end %>
<%= footer_template(config, module) %>
<%= for {name, nodes} <- summary, nodes != [], key = HTML.text_to_id(name) do %>
<section id="<%= key %>" class="details-list">
<h1 class="section-heading">
<a class="hover-link" href="#<%= key %>">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this section</span>
</a>
<%= name %>
</h1>
<div class="<%= key %>-list">
<%= for node <- nodes, do: detail_template(node, module) %>
</div>
</section>
<% end %>
<%= footer_template(config, module) %>
6 changes: 3 additions & 3 deletions lib/ex_doc/formatter/html/templates/sidebar_template.eex
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
<% url = config.homepage_url || "#{config.main}.html" %>
<div class="sidebar-header">
<div class="sidebar-projectDetails">
<a href="<%= url %>" class="sidebar-projectName">
<a href="<%= url %>" class="sidebar-projectName" translate="no">
<%= config.project %>
</a>
<strong class="sidebar-projectVersion">
<strong class="sidebar-projectVersion" translate="no">
v<%= config.version %>
</strong>
</div>
Expand All @@ -47,7 +47,7 @@
<% end %>

<%= if nodes_map.tasks != [] do %>
<li><a id="tasks-list-link" href="#full-list">Mix Tasks</a></li>
<li><a id="tasks-list-link" href="#full-list"><span translate="no">Mix</span> Tasks</a></li>
<% end %>
</ul>
<div class="gradient"></div>
Expand Down
11 changes: 0 additions & 11 deletions lib/ex_doc/formatter/html/templates/summary_entry_template.eex

This file was deleted.

14 changes: 13 additions & 1 deletion lib/ex_doc/formatter/html/templates/summary_template.eex
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
<h2>
<a href="#<%= HTML.text_to_id(name) %>"><%= name %></a>
</h2>
<%= for node <- nodes, do: summary_entry_template(node) %>
<%= for node <- nodes do %>
<div class="summary-row">
<div class="summary-signature">
<a href="#<%=enc node.id %>" translate="no"><%=h node.signature %></a>
<%= if deprecated = node.deprecated do %>
<span class="deprecated" title="<%= h(deprecated) %>">deprecated</span>
<% end %>
</div>
<%= if doc = node.rendered_doc do %>
<div class="summary-synopsis"><%= synopsis(doc) %></div>
<% end %>
</div>
<% end %>
</div>
<% end %>
2 changes: 1 addition & 1 deletion test/ex_doc/formatter/epub/templates_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ defmodule ExDoc.Formatter.EPUB.TemplatesTest do

test "outputs summaries" do
content = get_module_page([CompiledWithDocs])
assert content =~ ~r{<div class="summary-signature">\s*<a href="#example_1/0">}
assert content =~ ~r{<div class="summary-signature">\s*<a href="#example_1/0" translate="no">}
end

test "contains links to summary sections when those exist" do
Expand Down
Loading

0 comments on commit add7a0d

Please sign in to comment.