iconv-go icon indicating copy to clipboard operation
iconv-go copied to clipboard

ASCII translit not working

Open pierrre opened this issue 11 years ago • 3 comments

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"

pierrre avatar Feb 05 '14 14:02 pierrre

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

djimenez avatar Feb 05 '14 19:02 djimenez

Yes it works! :) I get "ae" as expected.

pierrre avatar Feb 06 '14 09:02 pierrre

I had the same problem in PHP. I fixed it with a locale tweak/setting.

pierrre avatar Feb 06 '14 09:02 pierrre