1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-11-19 20:31:46 +02:00

Doc: Allow translating website

This commit is contained in:
Laurent Cozic 2022-11-22 18:16:57 +00:00
parent 07fc6aa647
commit c990e81def
29 changed files with 796 additions and 146 deletions

View File

@ -2307,15 +2307,27 @@ packages/tools/update-readme-sponsors.js.map
packages/tools/updateMarkdownDoc.d.ts
packages/tools/updateMarkdownDoc.js
packages/tools/updateMarkdownDoc.js.map
packages/tools/utils/translation.d.ts
packages/tools/utils/translation.js
packages/tools/utils/translation.js.map
packages/tools/website/build.d.ts
packages/tools/website/build.js
packages/tools/website/build.js.map
packages/tools/website/buildTranslations.d.ts
packages/tools/website/buildTranslations.js
packages/tools/website/buildTranslations.js.map
packages/tools/website/updateDownloadPage.d.ts
packages/tools/website/updateDownloadPage.js
packages/tools/website/updateDownloadPage.js.map
packages/tools/website/updateNews.d.ts
packages/tools/website/updateNews.js
packages/tools/website/updateNews.js.map
packages/tools/website/utils/applyTranslations.d.ts
packages/tools/website/utils/applyTranslations.js
packages/tools/website/utils/applyTranslations.js.map
packages/tools/website/utils/applyTranslations.test.d.ts
packages/tools/website/utils/applyTranslations.test.js
packages/tools/website/utils/applyTranslations.test.js.map
packages/tools/website/utils/frontMatter.d.ts
packages/tools/website/utils/frontMatter.js
packages/tools/website/utils/frontMatter.js.map
@ -2334,6 +2346,9 @@ packages/tools/website/utils/parser.js.map
packages/tools/website/utils/pressCarousel.d.ts
packages/tools/website/utils/pressCarousel.js
packages/tools/website/utils/pressCarousel.js.map
packages/tools/website/utils/processTranslations.d.ts
packages/tools/website/utils/processTranslations.js
packages/tools/website/utils/processTranslations.js.map
packages/tools/website/utils/render.d.ts
packages/tools/website/utils/render.js
packages/tools/website/utils/render.js.map

15
.gitignore vendored
View File

@ -2295,15 +2295,27 @@ packages/tools/update-readme-sponsors.js.map
packages/tools/updateMarkdownDoc.d.ts
packages/tools/updateMarkdownDoc.js
packages/tools/updateMarkdownDoc.js.map
packages/tools/utils/translation.d.ts
packages/tools/utils/translation.js
packages/tools/utils/translation.js.map
packages/tools/website/build.d.ts
packages/tools/website/build.js
packages/tools/website/build.js.map
packages/tools/website/buildTranslations.d.ts
packages/tools/website/buildTranslations.js
packages/tools/website/buildTranslations.js.map
packages/tools/website/updateDownloadPage.d.ts
packages/tools/website/updateDownloadPage.js
packages/tools/website/updateDownloadPage.js.map
packages/tools/website/updateNews.d.ts
packages/tools/website/updateNews.js
packages/tools/website/updateNews.js.map
packages/tools/website/utils/applyTranslations.d.ts
packages/tools/website/utils/applyTranslations.js
packages/tools/website/utils/applyTranslations.js.map
packages/tools/website/utils/applyTranslations.test.d.ts
packages/tools/website/utils/applyTranslations.test.js
packages/tools/website/utils/applyTranslations.test.js.map
packages/tools/website/utils/frontMatter.d.ts
packages/tools/website/utils/frontMatter.js
packages/tools/website/utils/frontMatter.js.map
@ -2322,6 +2334,9 @@ packages/tools/website/utils/parser.js.map
packages/tools/website/utils/pressCarousel.d.ts
packages/tools/website/utils/pressCarousel.js
packages/tools/website/utils/pressCarousel.js.map
packages/tools/website/utils/processTranslations.d.ts
packages/tools/website/utils/processTranslations.js
packages/tools/website/utils/processTranslations.js.map
packages/tools/website/utils/render.d.ts
packages/tools/website/utils/render.js
packages/tools/website/utils/render.js.map

2
Assets/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*~
WebsiteAssets/locales/*.mo

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 MiB

View File

@ -399,12 +399,12 @@ div.navbar-mobile-content a.sponsor-button {
margin: auto;
}
#top-section-img {
.top-section-img {
margin-bottom: -280px;
margin-top: 40px;
}
#top-section-img img {
.top-section-img img {
width: 100%;
}
@ -910,7 +910,7 @@ footer .bottom-links-row p {
padding-top: 80px;
}
#top-section-img {
.top-section-img {
margin-bottom: -90px;
margin-top: 50px;
}
@ -1154,7 +1154,7 @@ footer .bottom-links-row p {
background-position: bottom;
padding-bottom: 160px;
}
#top-section-img {
.top-section-img {
margin-bottom: -240px;
margin-top: 130px;
}
@ -1182,3 +1182,25 @@ footer .bottom-links-row p {
margin-top: -15p;
}
}
/*****************************************************************
ENGLISH VERSION
*****************************************************************/
:lang(en-gb) #made-in-france-section {
display: none;
}
:lang(en-gb) .top-section-img-cn {
display: none;
}
/*****************************************************************
CHINESE VERSION
*****************************************************************/
:lang(zh-cn) #in-the-press-section,
:lang(zh-cn) #sponsors-section,
:lang(zh-cn) .top-section-img-en {
display: none;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 149 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 320 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 582 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB

View File

@ -0,0 +1,28 @@
msgid ""
msgstr ""
"Project-Id-Version: \n"
"POT-Creation-Date: \n"
"PO-Revision-Date: \n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: fr_FR\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 3.0.1\n"
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:63
msgid "Download the app"
msgstr "Télécharger l'application"
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:54
msgid "Free your <span class=\"frame-bg frame-bg-blue\">notes</span>"
msgstr "Libérez vos <span class=\"frame-bg frame-bg-blue\">notes</span>"
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:57
msgid "Joplin is an open source note-taking app. Capture your thoughts and securely access them from any device."
msgstr "Joplin est une application libre de prise de notes. Capturez vos pensées et accédez-y de façon sécurisé depuis n'importe quel appareil."
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:65
msgid "Sign up with Joplin Cloud"
msgstr "S'inscrire sur Joplin Cloud"

View File

@ -0,0 +1,160 @@
msgid ""
msgstr ""
"Project-Id-Version: \n"
"POT-Creation-Date: \n"
"PO-Revision-Date: \n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: zh_CN\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 3.0.1\n"
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:192
msgid "<span class=\"frame-bg frame-bg-yellow-lg\">Customise</span> it"
msgstr "<span class=\"frame-bg frame-bg-yellow-lg\">定制</span>它 根据您的需要"
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:91
msgid "<span class=\"frame-bg frame-bg-yellow\">Multimedia</span> notes"
msgstr "<span class=\"frame-bg frame-bg-yellow\">多媒体</span>说明"
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:243
msgid "100% <span class=\"frame-bg frame-bg-yellow-lg\">your data</span>"
msgstr "百分之百<span class=\"frame-bg frame-bg-yellow-lg\">你的数据</span>"
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:271
msgid "A <span class=\"frame-bg frame-bg-yellow-lg\">French</span> Alternative"
msgstr "一个<span class=\"frame-bg frame-bg-yellow-lg\">法国</span>的替代方案"
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:223
msgid ""
"Access your notes from your computer, phone or tablet by synchronising with "
"various services, including Joplin Cloud, Dropbox and OneDrive. The app is "
"available on Windows, macOS, Linux, Android and iOS. A terminal app is also "
"available!"
msgstr ""
"通过与各种服务同步,包括Joplin Cloud、Dropbox和OneDrive,从你的电脑、手机或平"
"板电脑访问你的笔记。该应用程序可在Windows、macOS、Linux、Android和iOS上使用。"
"终端应用也可使用!"
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:195
msgid ""
"Customise the app with plugins, custom themes and multiple text editors "
"(Rich Text or Markdown). Or create your own scripts and plugins using the "
"Extension API."
msgstr ""
"用插件、自定义主题和多个文本编辑器(富文本或马克顿)来定制该应用程序。或者使"
"用扩展API创建你自己的脚本和插件。"
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:229
msgid "Download it now"
msgstr "下载该应用程序"
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:63
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:99
msgid "Download the app"
msgstr "下载该应用程序"
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:200
msgid "Find out more"
msgstr ""
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:54
msgid "Free your <span class=\"frame-bg frame-bg-blue\">notes</span>"
msgstr "释放你的<span class=\"frame-bg frame-bg-blue\">笔记</span>"
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:162
msgid "Get the clipper"
msgstr "获取剪子"
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:94
msgid ""
"Images, videos, PDFs and audio files are supported. Create math expressions "
"and diagrams directly from the app. Take photos with the mobile app and save "
"them to a note."
msgstr ""
"Joplin,由于其起源和设计,适应并尊重中国的标准和规则。这保证了您的使用不受限"
"制,以及您的使用数据的完全透明和安全。"
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:288
msgid "In the <span class=\"frame-bg frame-bg-yellow\">Press</span>"
msgstr ""
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:57
msgid ""
"Joplin is an open source note-taking app. Capture your thoughts and securely "
"access them from any device."
msgstr ""
"Joplin是一个开源的记事本应用程序。捕捉你的想法并从任何设备上安全地访问它们。"
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:274
msgid ""
"Joplin, due to its origin and design, adapts and respects Chinese standards "
"and rules. This guarantees your unrestricted use and complete transparency "
"and security of your usage data."
msgstr ""
"Joplin,由于其起源和设计,适应并尊重中国的标准和规则。这保证了您的使用不受限"
"制,以及您的使用数据的完全透明和安全。"
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:249
msgid "More about E2EE"
msgstr ""
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:352
msgid "Our <span class=\"frame-bg frame-bg-blue-lg\">sponsors</span>"
msgstr ""
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:154
msgid ""
"Save <span class=\"frame-bg frame-bg-blue\">web pages</span> <br>as notes"
msgstr "保存<span class=\"frame-bg frame-bg-blue\">网页</span> <br>作为笔记"
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:65
msgid "Sign up with Joplin Cloud"
msgstr "与乔布林云签约"
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:355
msgid "Thank you for your support!"
msgstr ""
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:244
msgid ""
"The app is open source and your notes are saved to an open format, so you'll "
"always have access to them. Uses End-To-End Encryption (E2EE) to secure your "
"notes and ensure no-one but yourself can access them."
msgstr ""
"该应用程序是开源的,你的笔记被保存为开放的格式,所以你将永远可以访问它们。使"
"用端对端加密(E2EE)来保护你的笔记,确保除了你自己之外没有人可以访问它们。"
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:131
msgid "Try it now"
msgstr "现在就试试吧"
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:157
msgid ""
"Use the web clipper extension, available on Chrome and Firefox, to save web "
"pages or take screenshots as notes."
msgstr "使用Chrome和Firefox上的web clipper扩展,可以保存网页或截图作为笔记。"
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:125
msgid ""
"With Joplin Cloud, share your notes with your friends, family or colleagues "
"and collaborate on them."
msgstr "通过乔普林云,与你的朋友、家人或同事分享你的笔记,并进行合作。"
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:124
msgid "Work <span class=\"frame-bg frame-bg-yellow\">together</span>"
msgstr "<span class=\"frame-bg frame-bg-yellow\">一起</span>工作"
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:128
msgid ""
"You can also publish a note to the internet and share the URL with others."
msgstr ""
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:220
msgid ""
"Your notes, <span class=\"frame-bg frame-bg-blue-lg\">everywhere</span> you "
"are"
msgstr ""
"你的笔记<span class=\"frame-bg frame-bg-blue-lg\">你在哪里都可以</span>"

View File

@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en">
<html lang="en-gb">
<head>
{{> gtmHead}}
{{> gaOptimize}}
@ -51,22 +51,22 @@
Running in {{env}} mode!
</div>
<h1 class="text-center">
<h1 translate class="text-center">
Free your <span class="frame-bg frame-bg-blue">notes</span>
</h1>
<p class="text-center" id="top-section-text">
<p translate class="text-center" id="top-section-text">
Joplin is an open source note-taking app. Capture your thoughts and securely access them from any device.
</p>
<br />
<br />
<p class="text-center">
<a href="{{baseUrl}}/download/" class="button-link btn-blue download-button">Download the app</a>
<a translate href="{{baseUrl}}/download/" class="button-link btn-blue download-button">Download the app</a>
{{#showJoplinCloudLinks}}
<a href="{{baseUrl}}/plans/" class="button-link btn-trans plans-button">Sign up with Joplin Cloud</a>
<a translate href="{{baseUrl}}/plans/" class="button-link btn-trans plans-button">Sign up with Joplin Cloud</a>
{{/showJoplinCloudLinks}}
</p>
<picture class="img-fluid img-center" id="top-section-img">
<picture class="img-fluid img-center top-section-img top-section-img-en">
<source type="image/webp" srcset="
{{imageBaseUrl}}/home-top-img-4x.webp 4820w,
{{imageBaseUrl}}/home-top-img-2x.webp 2388w,
@ -76,7 +76,20 @@
{{imageBaseUrl}}/home-top-img-2x.png 2388w,
{{imageBaseUrl}}/home-top-img.png 1205w
">
<img id="top-section-img-img" src="{{imageBaseUrl}}/home-top-img-2x.png">
<img src="{{imageBaseUrl}}/home-top-img-2x.png">
</picture>
<picture class="img-fluid img-center top-section-img top-section-img-cn">
<source type="image/webp" srcset="
{{imageBaseUrl}}/home-top-img-cn-4x.webp 4820w,
{{imageBaseUrl}}/home-top-img-cn-2x.webp 2388w,
{{imageBaseUrl}}/home-top-img-cn.webp 1205w
">
<source type="image/png" srcset="
{{imageBaseUrl}}/home-top-img-cn-2x.png 2388w,
{{imageBaseUrl}}/home-top-img-cn.png 1205w
">
<img src="{{imageBaseUrl}}/home-top-img-cn-2x.png">
</picture>
</div>
</div>
@ -88,17 +101,15 @@
<div class="row">
<div class="col-12 col-md-5 col-xxl-6">
<div class="ml-30 ml-mobile-0">
<h2 id="multimedia-title">
<h2 translate id="multimedia-title">
<span class="frame-bg frame-bg-yellow">Multimedia</span> notes
</h2>
<p id="multimedia-text">
Images, videos, PDFs and audio files are supported. Create
math expressions and diagrams directly from the app. Take
photos with the mobile app and save them to a note.
<p translate id="multimedia-text">
Images, videos, PDFs and audio files are supported. Create math expressions and diagrams directly from the app. Take photos with the mobile app and save them to a note.
</p>
<br />
<p>
<a href="{{baseUrl}}/download/" class="button-link btn-blue">Download the app</a>
<a translate href="{{baseUrl}}/download/" class="button-link btn-blue">Download the app</a>
</p>
</div>
</div>
@ -123,15 +134,14 @@
<div class="col-6 d-none d-md-block"></div>
<div class="col-12 col-md-6">
<div class="ml-30 ml-mobile-0">
<h2>Work <span class="frame-bg frame-bg-yellow">together</span></h2>
<p>
With Joplin Cloud, share your notes with your friends, family
or colleagues and collaborate on them.
<h2 translate>Work <span class="frame-bg frame-bg-yellow">together</span></h2>
<p translate>
With Joplin Cloud, share your notes with your friends, family or colleagues and collaborate on them.
</p>
<p>You can also publish a note to the internet and share the URL with others.</p>
<p translate>You can also publish a note to the internet and share the URL with others.</p>
<br/>
<p>
<a href="{{baseUrl}}/plans/" class="button-link btn-blue">Try it now</a>
<a translate href="{{baseUrl}}/plans/" class="button-link btn-blue">Try it now</a>
</p>
<br class="d-block d-md-none" />
<br class="d-block d-md-none" />
@ -154,16 +164,15 @@
<div class="row">
<div class="col-12 col-md-6">
<div class="ml-30 ml-mobile-0">
<h2 id="save-web-title">
<h2 translate id="save-web-title">
Save <span class="frame-bg frame-bg-blue">web pages</span> <br />as notes
</h2>
<p>
Use the web clipper extension, available on Chrome and
Firefox, to save web pages or take screenshots as notes.
<p translate>
Use the web clipper extension, available on Chrome and Firefox, to save web pages or take screenshots as notes.
</p>
<br />
<p>
<a href="{{baseUrl}}/clipper/" class="button-link btn-blue">Get the clipper</a>
<a translate href="{{baseUrl}}/clipper/" class="button-link btn-blue">Get the clipper</a>
</p>
</div>
</div>
@ -193,19 +202,15 @@
</div>
<div class="col-12 col-md-6">
<div class="ml-30 ml-mobile-0">
<h2 id="customise-it-title">
<h2 translate id="customise-it-title">
<span class="frame-bg frame-bg-yellow-lg">Customise</span> it
<br />
to your needs
</h2>
<p>
Customise the app with plugins, custom themes and multiple
text editors (Rich Text or Markdown). Or create your own
scripts and plugins using the Extension API.
<p translate>
Customise the app with plugins, custom themes and multiple text editors (Rich Text or Markdown). Or create your own scripts and plugins using the Extension API.
</p>
<br />
<p>
<a href="{{baseUrl}}/help/#plugins" class="button-link btn-blue">Find out more</a>
<a translate href="{{baseUrl}}/help/#plugins" class="button-link btn-blue">Find out more</a>
</p>
<br class="d-block d-lg-none" />
@ -225,16 +230,16 @@
<div class="container">
<div class="row">
<div class="col-12">
<h2 class="text-center">
<h2 translate class="text-center">
Your notes, <span class="frame-bg frame-bg-blue-lg">everywhere</span> you are
</h2>
<p class="text-center" id="your-note-text">
<p translate class="text-center" id="your-note-text">
Access your notes from your computer, phone or tablet by synchronising with various services, including Joplin Cloud, Dropbox and OneDrive. The app is available on Windows, macOS, Linux, Android and iOS. A terminal app is also available!
</p>
<br />
<br />
<p class="text-center">
<a href="{{baseUrl}}/download/" class="button-link btn-blue">Download it now</a>
<a translate href="{{baseUrl}}/download/" class="button-link btn-blue">Download it now</a>
</p>
<br />
</div>
@ -248,15 +253,13 @@
<div class="col-12 col-md-6">
<br class="d-block d-md-none" />
<div class="ml-30 ml-mobile-0">
<h2>100% <span class="frame-bg frame-bg-yellow-lg">your data</span></h2>
<p>
The app is open source and your notes are saved to an open
format, so you'll always have access to them. Uses End-To-End Encryption (E2EE) to secure your notes and ensure no-one but
yourself can access them.
<h2 translate>100% <span class="frame-bg frame-bg-yellow-lg">your data</span></h2>
<p translate>
The app is open source and your notes are saved to an open format, so you'll always have access to them. Uses End-To-End Encryption (E2EE) to secure your notes and ensure no-one but yourself can access them.
</p>
<br />
<p>
<a href="{{baseUrl}}/e2ee/" class="button-link btn-blue">More about E2EE</a>
<a translate href="{{baseUrl}}/e2ee/" class="button-link btn-blue">More about E2EE</a>
</p>
</div>
</div>
@ -274,12 +277,28 @@
</div>
</div>
<div id="made-in-france-section" class="blue-bg">
<div class="container">
<div class="row">
<div class="col-12">
<h2 translate class="text-center">
A <span class="frame-bg frame-bg-yellow-lg">French</span> Alternative
</h2>
<p translate class="text-center">
Joplin, due to its origin and design, adapts and respects Chinese standards and rules. This guarantees your unrestricted use and complete transparency and security of your usage data.
</p>
<br /><br /><br /><br />
</div>
</div>
</div>
</div>
<div id="in-the-press-section">
<div class="container">
<div class="row">
<div class="col-12">
<br />
<h2 class="text-center">
<h2 translate class="text-center">
In the <span class="frame-bg frame-bg-yellow">Press</span>
</h2>
<br />
@ -343,10 +362,10 @@
<div class="container">
<div class="row">
<div class="col-12">
<h2 class="text-center">
<h2 translate class="text-center">
Our <span class="frame-bg frame-bg-blue-lg">sponsors</span>
</h2>
<p class="text-center" id="your-note-text">
<p translate class="text-center" id="your-note-text">
Thank you for your support!
</p>
<br />

View File

@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en">
<html lang="en-gb">
<!--

View File

@ -0,0 +1,112 @@
msgid ""
msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:192
msgid "<span class=\"frame-bg frame-bg-yellow-lg\">Customise</span> it"
msgstr ""
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:91
msgid "<span class=\"frame-bg frame-bg-yellow\">Multimedia</span> notes"
msgstr ""
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:243
msgid "100% <span class=\"frame-bg frame-bg-yellow-lg\">your data</span>"
msgstr ""
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:271
msgid "A <span class=\"frame-bg frame-bg-yellow-lg\">French</span> Alternative"
msgstr ""
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:223
msgid "Access your notes from your computer, phone or tablet by synchronising with various services, including Joplin Cloud, Dropbox and OneDrive. The app is available on Windows, macOS, Linux, Android and iOS. A terminal app is also available!"
msgstr ""
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:195
msgid "Customise the app with plugins, custom themes and multiple text editors (Rich Text or Markdown). Or create your own scripts and plugins using the Extension API."
msgstr ""
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:229
msgid "Download it now"
msgstr ""
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:63
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:99
msgid "Download the app"
msgstr ""
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:200
msgid "Find out more"
msgstr ""
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:54
msgid "Free your <span class=\"frame-bg frame-bg-blue\">notes</span>"
msgstr ""
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:162
msgid "Get the clipper"
msgstr ""
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:94
msgid "Images, videos, PDFs and audio files are supported. Create math expressions and diagrams directly from the app. Take photos with the mobile app and save them to a note."
msgstr ""
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:288
msgid "In the <span class=\"frame-bg frame-bg-yellow\">Press</span>"
msgstr ""
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:57
msgid "Joplin is an open source note-taking app. Capture your thoughts and securely access them from any device."
msgstr ""
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:274
msgid "Joplin, due to its origin and design, adapts and respects Chinese standards and rules. This guarantees your unrestricted use and complete transparency and security of your usage data."
msgstr ""
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:249
msgid "More about E2EE"
msgstr ""
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:352
msgid "Our <span class=\"frame-bg frame-bg-blue-lg\">sponsors</span>"
msgstr ""
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:154
msgid "Save <span class=\"frame-bg frame-bg-blue\">web pages</span> <br>as notes"
msgstr ""
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:65
msgid "Sign up with Joplin Cloud"
msgstr ""
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:355
msgid "Thank you for your support!"
msgstr ""
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:244
msgid "The app is open source and your notes are saved to an open format, so you'll always have access to them. Uses End-To-End Encryption (E2EE) to secure your notes and ensure no-one but yourself can access them."
msgstr ""
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:131
msgid "Try it now"
msgstr ""
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:157
msgid "Use the web clipper extension, available on Chrome and Firefox, to save web pages or take screenshots as notes."
msgstr ""
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:125
msgid "With Joplin Cloud, share your notes with your friends, family or colleagues and collaborate on them."
msgstr ""
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:124
msgid "Work <span class=\"frame-bg frame-bg-yellow\">together</span>"
msgstr ""
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:128
msgid "You can also publish a note to the internet and share the URL with others."
msgstr ""
#: /Users/laurent/src/joplin/Assets/WebsiteAssets/templates/front.mustache:220
msgid "Your notes, <span class=\"frame-bg frame-bg-blue-lg\">everywhere</span> you are"
msgstr ""

View File

@ -6,15 +6,9 @@
],
"settings": {
"files.exclude": {
".yarn": true,
"lerna-debug.log": true,
"_mydocs/mdtest/": true,
"./packages/lib/plugin_types": true,
"_releases/": true,
"_vieux/": true,
".gitignore": true,
".eslintignore": true,
"**/*.jpl": true,
"./packages/app-cli/**/*.*~": true,
"./packages/app-cli/**/*.mo": true,
"./packages/app-cli/**/build/": true,
@ -103,26 +97,32 @@
"./packages/app-mobile/fastlane/Preview.html": true,
"./packages/app-mobile/fastlane/report.xml": true,
"./packages/app-mobile/fastlane/screenshots": true,
"./packages/renderer/**/.vscode/": true,
"./packages/renderer/**/copyLib.bat": true,
"./packages/renderer/**/node_modules/": true,
"./packages/app-tools/**/*-kct.*": true,
"./packages/app-tools/**/github_username_cache.json": true,
"./packages/app-tools/**/patreon_oauth_token.txt": true,
"./packages/lib/plugin_types": true,
"./packages/renderer/**/.vscode/": true,
"./packages/renderer/**/copyLib.bat": true,
"./packages/renderer/**/node_modules/": true,
".eslintignore": true,
".gitignore": true,
".vscode/*": true,
".yarn": true,
"*.sublime-workspace": true,
"**/_mydocs": true,
"**/_mydocs/EnexSamples/*.enex": true,
"**/_releases": true,
"**/_vieux/": true,
"**/.DS_Store": true,
"**/*?.js": { "when": "$(basename).tsx"},
"**/*.base64": true,
"**/*~": true,
"**/*.bundle.js": true,
"**/*.eot": true,
"**/*.icns": true,
"**/*.ico": true,
"**/*.jar": true,
"**/*.jpl": true,
"**/*.js": {"when": "$(basename).ts"},
"**/*.map": true,
"**/*.min.css": true,
"**/*.min.js": true,
@ -135,6 +135,7 @@
"**/*.ttf": true,
"**/*.woff": true,
"**/*.woff2": true,
"**/*~": true,
"**/app/data/uploads/": true,
"**/Clipper-source/": true,
"**/docs/*.html": true,
@ -171,11 +172,13 @@
"app/config/parameters.yml": true,
"app/data/uploads/.gitkeep": false,
"Assets/DownloadBadges*.psd": true,
"Assets/TinyMCE/langs": true,
"Assets/WebsiteAssets/locales/*.mo": true,
"build/": true,
"docs/": true,
"docs/images/flags": true,
"lerna-debug.log": true,
"node_modules/": true,
"Assets/TinyMCE/langs": true,
"packages/app-cli/**/*.*~": true,
"packages/app-cli/**/*.mo": true,
"packages/app-cli/**/build/": true,
@ -224,7 +227,6 @@
"packages/app-cli/tests/support/plugins/toc/**/dist/": true,
"packages/app-cli/tests/sync/": true,
"packages/app-cli/tests/tmp/": true,
"packages/htmlpack/dist/": true,
"packages/app-clipper/**/dist/": true,
"packages/app-clipper/content_scripts/**/*.bundle.js": true,
"packages/app-clipper/dist/": true,
@ -250,7 +252,6 @@
"packages/app-desktop/**/pluginAssets/": true,
"packages/app-desktop/build/icons/": true,
"packages/app-desktop/build/images/": true,
"packages/app-desktop/vendor/lib/": true,
"packages/app-desktop/dist/": true,
"packages/app-desktop/fonts/": true,
"packages/app-desktop/gui/note-viewer/highlight/styles/": true,
@ -258,6 +259,7 @@
"packages/app-desktop/gui/NoteEditor/NoteBody/TinyMCE/supportedLocales.js": true,
"packages/app-desktop/lib/": true,
"packages/app-desktop/locale/": true,
"packages/app-desktop/vendor/lib/": true,
"packages/app-mobile/**/.DS_Store": true,
"packages/app-mobile/**/.gradle": true,
"packages/app-mobile/**/.idea": true,
@ -305,6 +307,16 @@
"packages/app-mobile/fastlane/screenshots": true,
"packages/app-mobile/ios/build/": true,
"packages/app-mobile/lib/csstojs/": true,
"packages/app-mobile/lib/rnInjectedJs/": true,
"packages/app-mobile/lib/sql-extensions/spellfix.so": true,
"packages/app-mobile/node_modules/": true,
"packages/app-tools/**/*-kct.*": true,
"packages/app-tools/**/github_username_cache.json": true,
"packages/app-tools/**/patreon_oauth_token.txt": true,
"packages/app-tools/commit_hook.txt": true,
"packages/app-tools/github_oauth_token.txt": true,
"packages/generator-joplin/generators/app/templates/api/": true,
"packages/htmlpack/dist/": true,
"packages/renderer/**/.vscode/": true,
"packages/renderer/**/copyLib.bat": true,
"packages/renderer/**/node_modules/": true,
@ -312,22 +324,13 @@
"packages/renderer/MdToHtml/rules/fence.js": true,
"packages/renderer/MdToHtml/rules/mermaid.js": true,
"packages/renderer/MdToHtml/rules/sanitize_html.js": true,
"packages/app-mobile/lib/rnInjectedJs/": true,
"packages/app-mobile/lib/sql-extensions/spellfix.so": true,
"packages/server/dist/": true,
"packages/server/db-*.sqlite": true,
"packages/server/test.pid": true,
"packages/server/dist/": true,
"packages/server/temp": true,
"packages/generator-joplin/generators/app/templates/api/": true,
"packages/app-mobile/node_modules/": true,
"packages/server/test.pid": true,
"phpunit.xml": true,
"Server/db*.sqlite/": true,
"Server/dist/": true,
"packages/app-tools/**/*-kct.*": true,
"packages/app-tools/**/github_username_cache.json": true,
"packages/app-tools/**/patreon_oauth_token.txt": true,
"packages/app-tools/commit_hook.txt": true,
"packages/app-tools/github_oauth_token.txt": true,
"var/*": true,
"var/cache": false,
"var/cache/.gitkeep": false,
@ -342,8 +345,6 @@
"vendor/": true,
"web/bundles/": true,
"web/env.php": true,
"**/*.js": {"when": "$(basename).ts"},
"**/*?.js": { "when": "$(basename).tsx"},
}
}
}

View File

@ -21,6 +21,7 @@
"updateNews": "node ./packages/tools/website/updateNews",
"buildSettingJsonSchema": "yarn workspace joplin start settingschema ../../../joplin-website/docs/schema/settings.json",
"buildTranslations": "node packages/tools/build-translation.js",
"buildWebsiteTranslations": "node packages/tools/website/buildTranslations.js",
"buildWebsite": "node ./packages/tools/website/build.js && yarn run buildPluginDoc && yarn run buildSettingJsonSchema",
"checkLibPaths": "node ./packages/tools/checkLibPaths.js",
"circularDependencyCheck": "madge --warning --circular --extensions js ./",

View File

@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en">
<html lang="en-gb">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

View File

@ -37,7 +37,12 @@ class HtmlUtils {
for (const n in attr) {
if (!attr.hasOwnProperty(n)) continue;
output.push(`${n}="${htmlentities(attr[n])}"`);
if (!attr[n]) {
output.push(n);
} else {
output.push(`${n}="${htmlentities(attr[n])}"`);
}
}
return output.join(' ');

View File

@ -11,46 +11,16 @@ const rootDir = `${__dirname}/../..`;
const markdownUtils = require('@joplin/lib/markdownUtils').default;
const fs = require('fs-extra');
const gettextParser = require('gettext-parser');
const { translationExecutablePath, removePoHeaderDate, mergePotToPo, parsePoFile, parseTranslations } = require('./utils/translation');
const localesDir = `${__dirname}/locales`;
const libDir = `${rootDir}/packages/lib`;
const { execCommand, isMac, insertContentIntoFile, filename, dirname, fileExtension } = require('./tool-utils.js');
const { countryDisplayName, countryCodeOnly } = require('@joplin/lib/locale');
const { GettextExtractor, JsExtractors } = require('gettext-extractor');
function parsePoFile(filePath) {
const content = fs.readFileSync(filePath);
return gettextParser.po.parse(content);
}
function serializeTranslation(translation) {
const output = {};
// Translations are grouped by "msgctxt"
for (const msgctxt of Object.keys(translation.translations)) {
const translations = translation.translations[msgctxt];
for (const n in translations) {
if (!translations.hasOwnProperty(n)) continue;
if (n === '') continue;
const t = translations[n];
let translated = '';
if (t.comments && t.comments.flag && t.comments.flag.indexOf('fuzzy') >= 0) {
// Don't include fuzzy translations
} else {
translated = t['msgstr'][0];
}
if (translated) output[n] = translated;
}
}
// Sort the translations to make the diff easier to read.
const output = parseTranslations(translation);
return JSON.stringify(output, Object.keys(output).sort((a, b) => a.toLowerCase() < b.toLowerCase() ? -1 : +1), ' ');
}
@ -58,35 +28,12 @@ function saveToFile(filePath, data) {
fs.writeFileSync(filePath, data);
}
function buildLocale(inputFile, outputFile) {
const r = parsePoFile(inputFile);
async function buildLocale(inputFile, outputFile) {
const r = await parsePoFile(inputFile);
const translation = serializeTranslation(r);
saveToFile(outputFile, translation);
}
function executablePath(file) {
const potentialPaths = [
'/usr/local/opt/gettext/bin/',
'/opt/local/bin/',
'/usr/local/bin/',
];
for (const path of potentialPaths) {
const pathFile = path + file;
if (fs.existsSync(pathFile)) {
return pathFile;
}
}
throw new Error(`${file} could not be found. Please install via brew or MacPorts.\n`);
}
async function removePoHeaderDate(filePath) {
let sedPrefix = 'sed -i';
if (isMac()) sedPrefix += ' ""'; // Note: on macOS it has to be 'sed -i ""' (BSD quirk)
await execCommand(`${sedPrefix} -e'/POT-Creation-Date:/d' "${filePath}"`);
await execCommand(`${sedPrefix} -e'/PO-Revision-Date:/d' "${filePath}"`);
}
async function createPotFile(potFilePath) {
const excludedDirs = [
'./.git/*',
@ -225,16 +172,6 @@ async function createPotFile(potFilePath) {
await removePoHeaderDate(potFilePath);
}
async function mergePotToPo(potFilePath, poFilePath) {
let msgmergePath = 'msgmerge';
if (isMac()) msgmergePath = executablePath('msgmerge'); // Needs to have been installed with `brew install gettext`
const command = `${msgmergePath} -U "${poFilePath}" "${potFilePath}"`;
const result = await execCommand(command);
if (result && result.trim()) console.info(result.trim());
await removePoHeaderDate(poFilePath);
}
function buildIndex(locales, stats) {
const output = [];
output.push('var locales = {};');
@ -296,7 +233,7 @@ function translatorNameToMarkdown(translatorName) {
async function translationStatus(isDefault, poFile) {
// "apt install translate-toolkit" to have pocount
let pocountPath = 'pocount';
if (isMac()) pocountPath = executablePath('pocount');
if (isMac()) pocountPath = translationExecutablePath('pocount');
const command = `${pocountPath} "${poFile}"`;
const result = await execCommand(command);
@ -454,7 +391,7 @@ async function main() {
const poFilePäth = `${localesDir}/${locale}.po`;
const jsonFilePath = `${jsonLocalesDir}/${locale}.json`;
if (locale !== defaultLocale) await mergePotToPo(potFilePath, poFilePäth);
buildLocale(poFilePäth, jsonFilePath);
await buildLocale(poFilePäth, jsonFilePath);
const stat = await translationStatus(defaultLocale === locale, poFilePäth);
stat.locale = locale;

View File

@ -51,6 +51,10 @@ const sources: Source[] = [
id: 8,
name: 'WebsiteTopImage.png',
},
{
id: 9,
name: 'WebsiteTopImageCn.png',
},
];
function sourceById(id: number) {
@ -332,6 +336,41 @@ const operations: Operation[] = [
width: 1205,
height: 734,
},
// ============================================================================
// Website images CN
// ============================================================================
{
source: 9,
dest: 'Assets/WebsiteAssets/images/home-top-img-cn-4x.webp',
width: 4820,
height: 2938,
},
{
source: 9,
dest: 'Assets/WebsiteAssets/images/home-top-img-cn-2x.png',
width: 2388,
height: 1456,
},
{
source: 9,
dest: 'Assets/WebsiteAssets/images/home-top-img-cn-2x.webp',
width: 2388,
height: 1456,
},
{
source: 9,
dest: 'Assets/WebsiteAssets/images/home-top-img-cn.png',
width: 1205,
height: 734,
},
{
source: 9,
dest: 'Assets/WebsiteAssets/images/home-top-img-cn.webp',
width: 1205,
height: 734,
},
];
async function main() {

View File

@ -42,6 +42,7 @@
"yargs": "17.6.2"
},
"devDependencies": {
"@joplin/fork-htmlparser2": "^4.1.41",
"@rmp135/sql-ts": "1.15.1",
"@types/fs-extra": "9.0.13",
"@types/jest": "29.2.3",
@ -49,6 +50,7 @@
"@types/node": "18.11.9",
"gettext-extractor": "3.6.0",
"gulp": "4.0.2",
"html-entities": "1.4.0",
"jest": "29.3.1",
"rss": "1.2.2",
"sass": "1.56.1",

View File

@ -0,0 +1,72 @@
import { execCommand, isMac } from '../tool-utils';
import { existsSync, readFile } from 'fs-extra';
const gettextParser = require('gettext-parser');
export const removePoHeaderDate = async (filePath: string) => {
let sedPrefix = 'sed -i';
if (isMac()) sedPrefix += ' ""'; // Note: on macOS it has to be 'sed -i ""' (BSD quirk)
await execCommand(`${sedPrefix} -e'/POT-Creation-Date:/d' "${filePath}"`);
await execCommand(`${sedPrefix} -e'/PO-Revision-Date:/d' "${filePath}"`);
};
export const translationExecutablePath = (file: string) => {
const potentialPaths = [
'/usr/local/opt/gettext/bin/',
'/opt/local/bin/',
'/usr/local/bin/',
];
for (const path of potentialPaths) {
const pathFile = path + file;
if (existsSync(pathFile)) {
return pathFile;
}
}
throw new Error(`${file} could not be found. Please install via brew or MacPorts.\n`);
};
export const mergePotToPo = async (potFilePath: string, poFilePath: string) => {
let msgmergePath = 'msgmerge';
if (isMac()) msgmergePath = translationExecutablePath('msgmerge'); // Needs to have been installed with `brew install gettext`
const command = `${msgmergePath} -U "${poFilePath}" "${potFilePath}"`;
const result = await execCommand(command);
if (result && result.trim()) console.info(result.trim());
await removePoHeaderDate(poFilePath);
};
export const parsePoFile = async (filePath: string) => {
const content = await readFile(filePath);
return gettextParser.po.parse(content);
};
// Convert the gettext translations, as returned by `gettextParser.po.parse()`
// to a <string, string> map, with the English text on the left and the
// translation on the right. If a particular translation is missing, no entry
// will be returned. The caller should display the English text in this case.
export const parseTranslations = (gettextTranslations: any) => {
const output: Record<string, string> = {};
// Translations are grouped by "msgctxt"
for (const msgctxt of Object.keys(gettextTranslations.translations)) {
const translations = gettextTranslations.translations[msgctxt];
for (const n in translations) {
if (!translations.hasOwnProperty(n)) continue;
if (n === '') continue;
const t = translations[n];
let translated = '';
if (t.comments && t.comments.flag && t.comments.flag.indexOf('fuzzy') >= 0) {
// Don't include fuzzy translations
} else {
translated = t['msgstr'][0];
}
if (translated) output[n] = translated;
}
}
return output;
};

View File

@ -10,6 +10,8 @@ import { readmeFileTitle, replaceGitHubByWebsiteLinks } from './utils/parser';
import { extractOpenGraphTags } from './utils/openGraph';
import { readCredentialFileJson } from '@joplin/lib/utils/credentialFiles';
import { getNewsDateString } from './utils/news';
import { parsePoFile, parseTranslations } from '../utils/translation';
import processTranslations from './utils/processTranslations';
interface BuildConfig {
env: Env;
@ -389,6 +391,9 @@ async function main() {
url: 'https://joplinapp.org/news/',
},
});
const translations = parseTranslations(await parsePoFile(`${websiteAssetDir}/locales/zh_CN.po`));
await processTranslations(`${docDir}/index.html`, `${docDir}/cn/index.html`, 'zh-cn', translations);
}
main().catch((error) => {

View File

@ -0,0 +1,29 @@
import { rootDir } from '../tool-utils';
import { mergePotToPo } from '../utils/translation';
const { GettextExtractor, HtmlExtractors } = require('gettext-extractor');
const websiteAssetsDir = `${rootDir}/Assets/WebsiteAssets`;
const localesDir = `${websiteAssetsDir}/locales`;
const createPotFile = async (potFilePath: string) => {
const extractor = new GettextExtractor();
extractor
.createHtmlParser([
HtmlExtractors.elementContent('[translate]'),
])
.parseFile(`${websiteAssetsDir}/templates/front.mustache`);
extractor.savePotFile(potFilePath);
};
const main = async () => {
const potFilePath = `${websiteAssetsDir}/website.pot`;
await createPotFile(potFilePath);
await mergePotToPo(potFilePath, `${localesDir}/zh_CN.po`);
};
main().catch((error) => {
console.error(error);
process.exit(1);
});

View File

@ -0,0 +1,41 @@
import applyTranslations from './applyTranslations';
describe('applyTranslations', () => {
it('should apply translations', async () => {
const tests = [
{
html: '<div><span translate>Translate me</span></div>',
translations: {
'Translate me': 'Traduis moi',
},
htmlTranslated: '<div>\n<span translate>\nTraduis moi\n</span>\n</div>',
},
{
html: '<div><span translate>Missing translation</span></div>',
translations: {},
htmlTranslated: '<div>\n<span translate>\nMissing translation\n</span>\n</div>',
},
{
html: '<h1 translate class="text-center">\nFree your <span class="frame-bg frame-bg-blue">notes</span>\n</h1>',
translations: {
'Free your <span class="frame-bg frame-bg-blue">notes</span>': 'Libérez vos <span class="frame-bg frame-bg-blue">notes</span>',
},
htmlTranslated: '<h1 translate class="text-center">\nLibérez vos <span class="frame-bg frame-bg-blue">notes</span>\n</h1>',
},
{
html: '<div translate>Save <span class="frame-bg frame-bg-blue">web pages</span> <br />as notes</div>',
translations: {
'Save <span class="frame-bg frame-bg-blue">web pages</span> <br>as notes': 'Sauvegardez vos <span class="frame-bg frame-bg-blue">pages web</span> <br>en notes',
},
htmlTranslated: '<div translate>\nSauvegardez vos <span class="frame-bg frame-bg-blue">pages web</span> <br>en notes\n</div>',
},
];
for (const test of tests) {
const actual = applyTranslations(test.html, test.translations);
expect(actual).toEqual(test.htmlTranslated);
}
});
});

View File

@ -0,0 +1,131 @@
import { unique } from '@joplin/lib/ArrayUtils';
import htmlUtils from '@joplin/renderer/htmlUtils';
const Entities = require('html-entities').AllHtmlEntities;
const htmlentities = new Entities().encode;
const htmlparser2 = require('@joplin/fork-htmlparser2');
const trimHtml = (content: string) => {
return content
.replace(/\n/g, '')
.replace(/^(&tab;)+/i, '')
.replace(/^(&nbsp;)+/i, '')
.replace(/(&tab;)+$/i, '')
.replace(/(&nbsp;)+$/i, '');
};
const findTranslation = (englishString: string, translations: Record<string, string>): string => {
const stringsToTry = unique([
englishString,
englishString.replace(/<br\/>/gi, '<br>'),
englishString.replace(/<br \/>/gi, '<br>'),
englishString
.replace(/&apos;/gi, '\'')
.replace(/&quot;/gi, '"'),
]) as string[];
for (const stringToTry of stringsToTry) {
if (translations[stringToTry]) return translations[stringToTry];
}
return englishString;
};
export default (html: string, translations: Record<string, string>) => {
const output: string[] = [];
interface State {
// When inside a block that needs to be translated, this array
// accumulates the opening tags. For example, this text:
//
// <div translate>Hello <b>world</b></div>
//
// will have the tags ['div', 'b']
//
// This is used to track when we've processed all the content, including
// HTML content, within a translatable block. Once that stack is empty,
// we reached the end, and can translate the string that we got.
translateStack: string[];
// Keep a reference to the opening tag. For example in:
//
// <div translate>Hello <b>world</b></div>
//
// The opening tag is "div".
currentTranslationTag: string[];
// Once we finished processing the translable block, this will contain
// the string to be translated. It may contain HTML.
currentTranslationContent: string[];
// Tells if we're at the beginning of a translable block.
translateIsOpening: boolean;
}
const state: State = {
translateStack: [],
currentTranslationTag: [],
currentTranslationContent: [],
translateIsOpening: false,
};
const pushContent = (state: State, content: string) => {
if (state.translateStack.length) {
if (state.translateIsOpening) {
state.currentTranslationTag.push(content);
} else {
state.currentTranslationContent.push(content);
}
} else {
output.push(content);
}
};
const parser = new htmlparser2.Parser({
onopentag: (name: string, attrs: any) => {
if ('translate' in attrs) {
if (state.translateStack.length) throw new Error(`Cannot have a translate block within another translate block. At tag "${name}" attrs: ${JSON.stringify(attrs)}`);
state.translateStack.push(name);
state.currentTranslationContent = [];
state.currentTranslationTag = [];
state.translateIsOpening = true;
} else if (state.translateStack.length) {
state.translateStack.push(name);
}
let attrHtml = htmlUtils.attributesHtml(attrs);
if (attrHtml) attrHtml = ` ${attrHtml}`;
const closingSign = htmlUtils.isSelfClosingTag(name) ? '/>' : '>';
pushContent(state, `<${name}${attrHtml}${closingSign}`);
state.translateIsOpening = false;
},
ontext: (decodedText: string) => {
pushContent(state, htmlentities(decodedText));
},
onclosetag: (name: string) => {
if (state.translateStack.length) {
state.translateStack.pop();
if (!state.translateStack.length) {
const stringToTranslate = trimHtml(state.currentTranslationContent.join(''));
const translation = findTranslation(stringToTranslate, translations);
output.push(state.currentTranslationTag[0]);
output.push(translation);
}
}
if (htmlUtils.isSelfClosingTag(name)) return;
pushContent(state, `</${name}>`);
},
}, { decodeEntities: true });
parser.write(html);
parser.end();
return output.join('\n');
};

View File

@ -0,0 +1,12 @@
import { mkdirp, readFile, writeFile } from 'fs-extra';
import { dirname } from 'path';
import applyTranslations from './applyTranslations';
export default async (englishFilePath: string, translatedFilePath: string, languageCode: string, translations: Record<string, string>) => {
let content = await readFile(englishFilePath, 'utf8');
content = content.replace('<html lang="en-gb">', `<html lang="${languageCode}">`);
const translatedContent = await applyTranslations(content, translations);
const translatedDirname = dirname(translatedFilePath);
await mkdirp(translatedDirname);
await writeFile(translatedFilePath, translatedContent, 'utf8');
};

View File

@ -4658,6 +4658,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@joplin/tools@workspace:packages/tools"
dependencies:
"@joplin/fork-htmlparser2": ^4.1.41
"@joplin/lib": ^2.9.1
"@joplin/renderer": ^2.9.1
"@rmp135/sql-ts": 1.15.1
@ -4674,6 +4675,7 @@ __metadata:
gettext-parser: 6.0.0
glob: 8.0.3
gulp: 4.0.2
html-entities: 1.4.0
jest: 29.3.1
markdown-it: 13.0.1
md5-file: 5.0.0