From c77ba2814f5b380c8f076bc8431f8712fa7b0d2b Mon Sep 17 00:00:00 2001 From: hustcer Date: Tue, 8 Mar 2022 14:40:57 +0800 Subject: [PATCH 1/2] Update i18n meta data handling script --- i18n.nu | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/i18n.nu b/i18n.nu index 2402bf25c55..9a0ae015462 100644 --- a/i18n.nu +++ b/i18n.nu @@ -1,45 +1,53 @@ let meta = open 'i18n-meta.json' +# Update issue contents for https://github.com/nushell/nushell.github.io/issues/261 def update-i18n-status [] { - print 'This table holds the overview of the nushell docs writing and translation status. Welcome to participate in the translation of the docs. You can update the `i18n-meta.json` file when you have finished writing or translating the doc. Thanks' - print '' - print '---' - print '' + print "The following table holds the overview of the Nushell docs’ writing and translation status. Welcome to participate in the translation of the docs. And please update the `i18n-meta.json` file after you have finished writing or translating the doc. Thanks" + print $'(char nl)---(char nl)' ls -s book | where type == file && name != README.md | select name - | update en {|it| get-cell $it.name en } | default en 'In progress' - | update de {|it| get-cell $it.name de } | default de '-' - | update zh-cn {|it| get-cell $it.name zh-cn } | default zh-cn '-' - | update ja {|it| get-cell $it.name ja } | default ja '-' - | update es {|it| get-cell $it.name es } | default es '-' - | update pt-BR {|it| get-cell $it.name pt-BR } | default pt-BR '-' + | update en {|it| get-cell $it.name en } + | update de {|it| get-cell $it.name de } + | update zh-cn {|it| get-cell $it.name zh-cn } + | update ja {|it| get-cell $it.name ja } + | update es {|it| get-cell $it.name es } + | update pt-BR {|it| get-cell $it.name pt-BR } | to md --pretty - print '' - print 'Possible status values: `-`,`Completed`,`In Progress`,`Being translated by @ABC`' + print $'(char nl)Possible status values: `-`,`Completed`,`In Progress`,`Being translated by @ABC`(char nl)' } def get-cell [ name: string lng: string ] { - ($meta | where name == $name | get $lng | get 0) + let match = ($meta | where name == $name) + let cellDefault = if ($lng == 'en') { 'In progress' } else { '-' } + # For newly added docs + if ($match | length) == 0 { + $cellDefault + + } else { # For existing docs + let val = ($match | get $lng | get 0) + if ($val | empty?) { $cellDefault } else { $val } + } } +# Generate or update meta data for docs' translation status def gen-i18n-meta [] { ls -s book | where type == file && name != README.md | select name - | update en 'In progress' - | update de '-' - | update zh-cn '-' - | update ja '-' - | update es '-' - | update pt-BR '-' + | update en {|it| get-cell $it.name en } + | update de {|it| get-cell $it.name de } + | update zh-cn {|it| get-cell $it.name zh-cn } + | update ja {|it| get-cell $it.name ja } + | update es {|it| get-cell $it.name es } + | update pt-BR {|it| get-cell $it.name pt-BR } | to json -i 2 | save -r i18n-meta.json } From aab4ae6e4472c6a767fdb0262eb15a29c6c6ebfd Mon Sep 17 00:00:00 2001 From: hustcer Date: Tue, 8 Mar 2022 15:25:45 +0800 Subject: [PATCH 2/2] Add meta file existence check --- i18n.nu | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/i18n.nu b/i18n.nu index 9a0ae015462..dfedc41f97b 100644 --- a/i18n.nu +++ b/i18n.nu @@ -1,5 +1,9 @@ -let meta = open 'i18n-meta.json' +let META_FILE = 'i18n-meta.json' +if ($META_FILE | path exists) == false { + echo '[]' | save -r $META_FILE +} +let meta = open $META_FILE # Update issue contents for https://github.com/nushell/nushell.github.io/issues/261 def update-i18n-status [] {