Skip to content

Instantly share code, notes, and snippets.

@kjk
Created February 1, 2020 20:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kjk/92beff9f2412c120b31663e6f49b0e38 to your computer and use it in GitHub Desktop.
Save kjk/92beff9f2412c120b31663e6f49b0e38 to your computer and use it in GitHub Desktop.
extract translations with regexp (made with https://codeeval.dev)
package main
import (
"fmt"
"regexp"
)
var (
TRANSLATION_PATTERN = regexp.MustCompile(`\b_TRN?\("(.*?)"\)`)
)
const (
src = `
{ _TRN("&Close\tCtrl+W"), IDM_CLOSE, MF_REQ_DISK_ACCESS },
blaha
{ _TRN("P&roperties\tCtrl+D"), IDM_PROPERTIES, 0 },
`
)
func extractTranslations(s string) []string {
var res []string
a := TRANSLATION_PATTERN.FindAllStringSubmatch(s, -1)
for _, el := range a {
res = append(res, el[1])
}
return res
}
func main() {
a := extractTranslations(src)
fmt.Printf("Translations; %#v\n", a)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment