The code tested, but maybe it sucks.
1. striping @xx, _TT: when mapping with full name failed, we check if there's a '@' in locname. if so, go back to the part of copying catname, override and skip '@xx'.
Then we check if there's a '_', and if both '@' and '_TT' is there, point locname to '@xx', set a correct loclen, go back to the part of writing locname to replace '_TT' with '@xx'. If not both, skip and simply override '_TT'.
Because there's also '_' in 'LC_xx', we may get into a dead loop of stripping '_TT'. So locname is checked, it's set to NULL if we used strchr to skip once.
Same reason, we may get into a dead loop of overriding '_TT'. The first position of '/' should be front of the '_' if we replaced it once, the name will like: 'zh@t/LC_xx'.
zh_CN@t (stripped by the first part)-> zh_CN (overrided by the second part)-> zh@t (stripped by the first part again)-> zh
2. about rewriting of '.GBK': I agreeded with keeping the original value of user, and stripping it in gettext() before. But i thought that someone may validate if libc set the correct charset by setlocale(). So we should rewrite .XX to .UTF-8 in setlocale(), we cant return a wrong value in principle.