| 1 |
// generates the fixtures/fonts.html for testing the fonts in docker. |
| 2 |
// Use the google translate to translate "test" into all the languages, print the result into a html page. |
| 3 |
// By reviewing the generated pdf we can find out what font is missing for a specific language. |
| 4 |
|
| 5 |
// Package main ... |
| 6 |
package main |
| 7 |
|
| 8 |
import ( |
| 9 |
"fmt" |
| 10 |
"log" |
| 11 |
|
| 12 |
"github.com/go-rod/rod" |
| 13 |
"github.com/go-rod/rod/lib/launcher" |
| 14 |
"github.com/go-rod/rod/lib/utils" |
| 15 |
) |
| 16 |
|
| 17 |
func main() { |
| 18 |
url := launcher.New().MustLaunch() |
| 19 |
b := rod.New().ControlURL(url).MustConnect() |
| 20 |
defer b.MustClose() |
| 21 |
|
| 22 |
p := b.MustPage("https://translate.google.com/") |
| 23 |
|
| 24 |
p.MustElement("#source").MustInput("Test the google translate.") |
| 25 |
|
| 26 |
if p.MustHas(".tlid-dismiss-button") { |
| 27 |
p.MustElement(".tlid-dismiss-button").MustClick() |
| 28 |
} |
| 29 |
|
| 30 |
showList := p.MustElement(".tlid-open-target-language-list") |
| 31 |
list := p.MustElements(".language-list:nth-child(2) .language_list_section:nth-child(2) .language_list_item_language_name") |
| 32 |
|
| 33 |
html := "" |
| 34 |
|
| 35 |
for _, lang := range list { |
| 36 |
showList.MustClick() |
| 37 |
wait := p.MustWaitRequestIdle() |
| 38 |
lang.MustClick() |
| 39 |
wait() |
| 40 |
name := lang.MustText() |
| 41 |
result := p.MustElement(".tlid-translation").MustText() |
| 42 |
log.Println(name, result) |
| 43 |
html += fmt.Sprintf("<tr><td>%s</td><td>%s</td></tr>\n", name, result) |
| 44 |
} |
| 45 |
|
| 46 |
html = fmt.Sprintf(`<html> |
| 47 |
<p style="font-family: serif;"> |
| 48 |
This file is generated by <code>"fixtures/gen-fonts"</code> |
| 49 |
</p> |
| 50 |
<p>Test smileys: 😀 😁 😂 🤣 😃 😄 😅 😆 😉 😊 😋 😎 😍 😘 🥰 😗 😙 😚</p> |
| 51 |
<table> |
| 52 |
%s |
| 53 |
</table></html>`, |
| 54 |
html, |
| 55 |
) |
| 56 |
|
| 57 |
utils.E(utils.OutputFile("fixtures/fonts.html", html)) |
| 58 |
} |