Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update i18n meta data handling script #266

Merged
merged 2 commits into from
Mar 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
52 changes: 32 additions & 20 deletions i18n.nu
Original file line number Diff line number Diff line change
@@ -1,45 +1,57 @@

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 [] {

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
}
Expand Down