|
| 1 | +// SPDX-License-Identifier: Apache-2.0 |
| 2 | + |
| 3 | +package executor |
| 4 | + |
| 5 | +import ( |
| 6 | + "fmt" |
| 7 | +) |
| 8 | + |
| 9 | +// showLanguages lists all languages found in the project's translatable strings. |
| 10 | +// Requires REFRESH CATALOG FULL to populate the strings table. |
| 11 | +func (e *Executor) showLanguages() error { |
| 12 | + if e.catalog == nil { |
| 13 | + return fmt.Errorf("no catalog available — run REFRESH CATALOG FULL first") |
| 14 | + } |
| 15 | + |
| 16 | + result, err := e.catalog.Query(` |
| 17 | + SELECT Language, COUNT(*) as StringCount |
| 18 | + FROM strings |
| 19 | + WHERE Language != '' |
| 20 | + GROUP BY Language |
| 21 | + ORDER BY StringCount DESC |
| 22 | + `) |
| 23 | + if err != nil { |
| 24 | + return fmt.Errorf("failed to query languages: %w", err) |
| 25 | + } |
| 26 | + |
| 27 | + if len(result.Rows) == 0 { |
| 28 | + fmt.Fprintln(e.output, "No translatable strings found. Run REFRESH CATALOG FULL to populate the strings table.") |
| 29 | + return nil |
| 30 | + } |
| 31 | + |
| 32 | + // Print table |
| 33 | + fmt.Fprintf(e.output, "| %-10s | %s |\n", "Language", "Strings") |
| 34 | + fmt.Fprintf(e.output, "|%-12s|%s|\n", "------------", "---------") |
| 35 | + for _, row := range result.Rows { |
| 36 | + lang := "" |
| 37 | + count := "" |
| 38 | + if len(row) > 0 { |
| 39 | + lang = fmt.Sprintf("%v", row[0]) |
| 40 | + } |
| 41 | + if len(row) > 1 { |
| 42 | + count = fmt.Sprintf("%v", row[1]) |
| 43 | + } |
| 44 | + fmt.Fprintf(e.output, "| %-10s | %7s |\n", lang, count) |
| 45 | + } |
| 46 | + |
| 47 | + fmt.Fprintf(e.output, "\n(%d languages)\n", len(result.Rows)) |
| 48 | + return nil |
| 49 | +} |
0 commit comments