Merge pull request 'Host translate.joinplu.me on Netlify' (#42) from netlify into main

Reviewed-on: plume/joinplu.me#42
main
KitaitiMakoto 3 years ago
commit 73710f46ba

6
.gitignore vendored

@ -3,5 +3,9 @@
.DS_Store
.sass-cache
build/
trans/
translate/
.po~
translations
# Local Netlify folder
.netlify

@ -5,7 +5,20 @@ like to contribute.
It is using middleman.
## Prerequisites
### Crowdin
- `crowdin` command v3
- Environment variable `CROWDIN_PERSONAL_TOKEN` (API token for Crowdin API v3)
### Netlify
- `netlify` command v2
- Environment variable `NETLIFY_AUTH_TOKEN`
## Usefull commands
- `middleman` for live preview during development
- `middleman build` when deploying
- `bundle exec rake build_site` when deploying
- `bundle exec rake deploy_trans` when deploying https://translate.joinplu.me/

@ -1,16 +1,34 @@
require "pathname"
BUILD_DIR = "build"
TRANS_DIR = "trans"
BUILD_DIR = Pathname("build")
LOCALE_DIR = Pathname("trans")
TRANS_DIR = Pathname("translate")
PSEUDO_LANG = "ach"
task :default => [:build_trans, "crowdin:upload", :build_site]
CROWDIN_SNIPPET = <<EOS
<script type="text/javascript">
var _jipt = [];
_jipt.push(['project', 'joinplume']);
_jipt.push(['escape', function() {
window.location.href = 'https://joinplu.me';
}]);
</script>
<script type="text/javascript" src="//cdn.crowdin.com/jipt/jipt.js"></script>
EOS
class Pathname
alias to_str to_s
end
task :default => [:build_trans, :build_site]
desc "Build site"
multitask :build_site => [:build_base, "crowdin:download"] do
Pathname.glob("#{TRANS_DIR}/**/*.html").select(&:file?).each do |path|
Pathname.glob("#{LOCALE_DIR}/**/*.html").select(&:file?).each do |path|
content = path.read
content.sub! /<script type="text\/javascript" src="\/\/cdn.crowdin.com\/jipt\/jipt.js"><\/script>/, ""
dest = Pathname(path.to_path.sub(TRANS_DIR, BUILD_DIR))
dest = Pathname(path.to_path.sub(LOCALE_DIR, BUILD_DIR))
$stderr.puts "copy #{path} -> #{dest}"
dest.parent.mkpath
dest.write content
@ -21,10 +39,25 @@ task :build_base do
sh "middleman", "build"
end
desc "Build site for translation"
task :build_trans do
env = {"CROWDIN" => "on"}
sh env, "middleman", "build", "--build-dir", TRANS_DIR
desc "Build site for translate.joinplu.me"
task :build_trans => "crowdin:download_pseudo" do
sh "middleman", "build", "--build-dir", TRANS_DIR
(LOCALE_DIR/PSEUDO_LANG).glob("**/*.html").each do |html|
doc = html.read
doc.sub! "<head>", "<head>" + CROWDIN_SNIPPET
dest = Pathname(html.to_path.sub(LOCALE_DIR/PSEUDO_LANG, TRANS_DIR))
dest.write doc
end
end
task :build_trans_src do
sh "middleman", "build", "--build-dir", LOCALE_DIR
end
desc "Deploy translate.joinplu.me"
task :deploy_trans => :build_trans do
sh "netlify", "deploy", "--dir", TRANS_DIR, "--prod"
end
namespace :crowdin do
@ -34,7 +67,11 @@ namespace :crowdin do
end
desc "Upload translation sources"
task :upload do
task :upload => :build_trans_src do
sh "crowdin", "upload", "sources"
end
task :download_pseudo do
sh "crowdin", "download", "--language", PSEUDO_LANG
end
end

@ -21,7 +21,7 @@ files: [
# Source files filter
# e.g. "/resources/en/*.json"
#
"source" : "/trans/index.html",
"source" : "/build/index.html",
#
# Where translations will be placed

@ -6,17 +6,6 @@
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Plume: a federated blogging application</title>
<% if ENV['CROWDIN'] == 'on' %>
<script type="text/javascript">
var _jipt = [];
_jipt.push(['project', 'joinplume']);
_jipt.push(['escape', function() {
window.location.href = 'https://joinplu.me';
}]);
</script>
<script type="text/javascript" src="//cdn.crowdin.com/jipt/jipt.js"></script>
<% end %>
<%= stylesheet_link_tag "site" %>
<%= javascript_include_tag "icons" %>
<link rel="icon" type="image/png" href="/images/favicon.png">

Loading…
Cancel
Save