iconv-go
iconv-go copied to clipboard
ASCII translit not working
My Go code:
package main
import (
"fmt"
iconv "github.com/djimenez/iconv-go"
)
func main() {
su := "aé"
sa, err := iconv.ConvertString(su, "UTF-8", "ASCII//TRANSLIT")
if err != nil {
panic(err)
}
fmt.Println(sa)
}
Result:
a?
Expected result:
ae
Native iconv command:
echo "aé" | iconv -f "UTF-8" -t "ASCII//TRANSLIT"
This was odd, I didn't see any immediate reason why this shouldn't work for you - since I'm passing the provided strings directly to the iconv_open without any manipulation.
When I looked at the main function for the iconv program however, i saw they were doing a setlocale(LC_ALL, "") before opening an iconv descriptor and processing data.
When I did a similar call with cgo in an init method, everything worked as expected. I'm not sure if that's appropriate for my library to do though. There doesn't already seem to be a way to do the same as setlocale without using cgo, which makes me worry its not a very nice thing to just do.
I'll put the change on a branch until i know more
Yes it works! :) I get "ae" as expected.
I had the same problem in PHP. I fixed it with a locale tweak/setting.