Skip to content

Commit 586d5a9

Browse files
committed
chore: 英語トグル機能を追加
1 parent 162b177 commit 586d5a9

File tree

7 files changed

+165
-1
lines changed

7 files changed

+165
-1
lines changed

public/_includes/_main-nav.jade

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ md-toolbar(class="main-nav background-regal l-pinned-top l-layer-5",scroll-y-off
1313
li.l-left <a class="main-nav-button" href="/events.html" md-button>Events</a>
1414
li.l-left <a class="main-nav-button" href="/news.html" md-button>News</a>
1515
li.l-right <a class="main-nav-button" href="/docs/ts/latest/quickstart.html" md-button>Get Started</a>
16+
li.l-right
17+
a.main-nav-button.md-button.ng-cloak(ng-click="appCtrl.toggleSource($event)", href)
18+
span {{appCtrl.sourceVisible?'Hide English':'Show English'}}

public/_includes/_scripts-include.jade

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ script(src="https://ajax.googleapis.com/ajax/libs/angular_material/1.0.0/angular
2020

2121

2222
<!-- Angular.io Site JS -->
23+
script(src="/localization/translate.js")
2324
script(src="/resources/js/site.js")
2425
script(src="/resources/js/util.js")
2526
script(src="/resources/js/controllers/app-controller.js")

public/docs/ts/latest/glossary.jade

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,21 @@ include _util-fns
44
:marked
55
# Angular 2 Glossary
66

7+
# Angular 2 用語集
8+
79
Angular 2 has a vocabulary of its own.
810
Most Angular 2 terms are everyday English words
911
with a specific meaning within the Angular system.
12+
13+
Angular2には独自の用語が存在します。
14+
ほとんどのAngular2の用語は日常英語の単語ですが、Angularシステムの中において特別な意味を有しています。
1015

1116
We have gathered here the most prominent terms
1217
and a few less familiar ones that have unusual or
1318
unexpected definitions.
1419

20+
ここには主要な用語といくつかのあまり馴染みのない用語を集めています。
21+
1522
[A](#A) [B](#B) [C](#C) [D](#D) [E](#E) [F](#F) [G](#G) [H](#H) [I](#I)
1623
[J](#J) [K](#K) [L](#L) [M](#M) [N](#N) [O](#O) [P](#P) [Q](#Q) [R](#R)
1724
[S](#S) [T](#T) [U](#U) [V](#V) [W](#W) [X](#X) [Y](#Y) [Z](#Z)

public/localization/translate.js

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
var sourceVisible = localStorage.getItem('source-visible') === 'true';
2+
3+
(function ($) {
4+
function addOriginalToggler() {
5+
var nodes = document.querySelectorAll('p, li, h1, h2, h3, h4, h5, h6, header, a, button, small');
6+
_.each(nodes, function (node) {
7+
var $node = $(node);
8+
9+
if (isLink(node) || isButton(node)) {
10+
$node.on('click', function (event) {
11+
event.stopPropagation();
12+
});
13+
14+
if (/^http?s:\/\//.test($node.attr('href')) && !$node.attr('target')) {
15+
$node.attr('target', '_blank');
16+
}
17+
}
18+
19+
var prevNode = node.previousElementSibling;
20+
var $prevNode = $(prevNode);
21+
22+
if (!prevNode) {
23+
return;
24+
}
25+
26+
if (isTranslationResult(node, prevNode)) {
27+
if ($prevNode.hasClass('nav-list-item') ||
28+
$prevNode.hasClass('l-right') ||
29+
$prevNode.hasClass('l-left')) {
30+
return;
31+
}
32+
if ($node.text() === $prevNode.text()) {
33+
return;
34+
}
35+
36+
$node.attr('id', prevNode.id);
37+
$node.addClass('translated');
38+
$prevNode.removeAttr('id');
39+
$prevNode.addClass('original-english');
40+
if (!sourceVisible) {
41+
$prevNode.addClass('hidden');
42+
}
43+
if (!isLink(node) && !isButton(node)) {
44+
var isDragging = false;
45+
$node.on('mousedown', function () {
46+
$(window).on('mousemove', function () {
47+
isDragging = true;
48+
$(window).unbind('mousemove');
49+
});
50+
});
51+
$prevNode.on('mousedown', function () {
52+
$(window).on('mousemove', function () {
53+
isDragging = true;
54+
$(window).unbind('mousemove');
55+
});
56+
});
57+
$node.on('mouseup', function () {
58+
var wasDragging = isDragging;
59+
isDragging = false;
60+
$(window).unbind('mousemove');
61+
if (!wasDragging) {
62+
$prevNode.toggleClass('hidden');
63+
}
64+
});
65+
$prevNode.on('mouseup', function () {
66+
var wasDragging = isDragging;
67+
isDragging = false;
68+
$(window).unbind('mousemove');
69+
if (!wasDragging) {
70+
$prevNode.addClass('hidden');
71+
}
72+
});
73+
}
74+
$node.after($prevNode);
75+
}
76+
})
77+
}
78+
79+
function attributesToString(node) {
80+
return _.chain(node.attributes)
81+
.map(function (value) {
82+
if (value.name === 'id') {
83+
return '';
84+
} else {
85+
return value.name + '=' + value.value;
86+
}
87+
})
88+
.sortBy()
89+
.value()
90+
.join(';');
91+
}
92+
93+
function isLink(node) {
94+
return node.tagName.toUpperCase() === 'A';
95+
}
96+
97+
function isButton(node) {
98+
return node.tagName.toUpperCase() === 'BUTTON';
99+
}
100+
101+
function isClonedNode(node1, node2) {
102+
return node1.tagName === node2.tagName &&
103+
attributesToString(node1) === attributesToString(node2);
104+
}
105+
106+
function indexOfSameType(node) {
107+
var i = 0;
108+
var aNode = node.parentNode.firstChild;
109+
while (aNode !== node) {
110+
++i;
111+
if (aNode.tagName !== node.tagName) {
112+
i = 0;
113+
}
114+
aNode = aNode.nextElementSibling;
115+
}
116+
return i;
117+
}
118+
119+
function isTranslationResult(node, prevNode) {
120+
return indexOfSameType(node) % 2 === 1 && isClonedNode(node, prevNode);
121+
}
122+
123+
addOriginalToggler();
124+
})(angular.element);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.original-english {
2+
border-top: 1px dashed $regal;
3+
&.hidden {
4+
display: none !important;
5+
}
6+
}
7+
8+
td, th {
9+
> p:last-child {
10+
margin-bottom: 0;
11+
}
12+
}

public/resources/css/main.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
@import 'theme';
1010
@import 'base/reset';
1111
@import 'base/type';
12+
@import 'translate';
1213
@import 'angular';
1314

1415

public/resources/js/controllers/app-controller.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,20 @@ angularIO.controller('AppCtrl', ['$mdDialog', '$timeout', '$http', '$sce', funct
6262

6363
// TRIGGER PRETTYPRINT AFTER DIGEST LOOP COMPLETE
6464
$timeout(prettyPrint, 1);
65-
} ]);
65+
66+
// TOGGLE TRANSLATIONS
67+
vm.sourceVisible = localStorage.getItem('source-visible') === 'true';
68+
vm.toggleSource = function ($event) {
69+
$event.preventDefault();
70+
vm.sourceVisible = !vm.sourceVisible;
71+
var nodes = document.querySelectorAll('.original-english');
72+
var $nodes = angular.element(nodes);
73+
if (vm.sourceVisible) {
74+
$nodes.removeClass('hidden');
75+
} else {
76+
$nodes.addClass('hidden');
77+
}
78+
localStorage.setItem('source-visible', vm.sourceVisible);
79+
}
80+
81+
}]);

0 commit comments

Comments
 (0)