Home > Software design >  Identify native character encoding and tranlate comments
Identify native character encoding and tranlate comments

Time:09-29

I have some source code that has comments in a foreign language. I can't tell what language this is, but the code came with a Chinese product. The documentation of the product is in Chinese, so I suspect that the source code shown below is also commented in Chinese. However, I suspect that there is a character encoding issue because the characters don't look Chinese - I see a combination of random characters. Maybe I just don't know the language.

Anyway, I'd like to know if anyone can suggest how I can translate this. Online translators are useless. Maybe if I can even somehow identify the correct character encoding set, then I could render the Chinese and just use google translate. This would help me a lot to understand how this code works.

    SCLK_INIT();//ϵͳʱÖÓÅäÖã¬Ê±ÖÓ16MHZ
    PC_DDR = 0xFF;     //·½Ïò¼Ä´æÆ    
    PC_CR1 = 0xFF;     //ÍÆÍìÊä³ö  
        
        PE_DDR = 0xFF;     //·½Ïò¼Ä´æÆ         
    PE_CR1 = 0xFF;     //ÍÆÍìÊä³ö 
        
        PD_DDR = 0xFC;     //·½Ïò¼Ä´æÆ÷      
    PD_CR1 = 0xFC;     //ÍÆÍìÊä³ö 
        PB_DDR = 0xEF;     //·½Ïò¼Ä´æÆ÷0001£¬111 PC¿ÚûÓеÍ0λ   PD0 SPICE          
    //PB_CR1 = 0xFF;     //ÍÆÍìÊä³ö 

CodePudding user response:

I ran some of the examples you provided through a script that basically tried every code page that iconv knows about, and looked for something that provided the cleanest results. That turned out to be CP936.

I then used iconv -f CP936 on a file with the content you provided and got the following result:

    SCLK_INIT();//脧碌脥鲁脢卤脰脫脜盲脰脙拢卢脢卤脰脫16MHZ
    PC_DDR = 0xFF;     //路陆脧貌录脛麓忙脝    
    PC_CR1 = 0xFF;     //脥脝脥矛脢盲鲁枚  
    
        PE_DDR = 0xFF;     //路陆脧貌录脛麓忙脝         
    PE_CR1 = 0xFF;     //脥脝脥矛脢盲鲁枚 
    
        PD_DDR = 0xFC;     //路陆脧貌录脛麓忙脝梅      
    PD_CR1 = 0xFC;     //脥脝脥矛脢盲鲁枚 
        PB_DDR = 0xEF;     //路陆脧貌录脛麓忙脝梅0001拢卢111 PC驴脷脙禄脫脨碌脥0脦禄   PD0 SPICE          
    //PB_CR1 = 0xFF;     //脥脝脥矛脢盲鲁枚 

To me this makes little sense when pulled through Google Translate, but this may make more sense to you, knowing the context of the code. I hope this helps you!

CodePudding user response:

I'm sure there are many ways to do this, but this is what worked for me:

Using the PlatformIO IDE, I could open the file and simply set the character encoding to "Chinese". Once I did this, the chinese characters were displayed and I could start translating them line-by-line. I'm sure there are utilities out there that one would want to use for projects larger than mine.

I'm certain almost any modern IDE will support character encoding, so just use your favorite one.

I initially had the file opened in Windows notepad and could not find a way to set the character encoding, hence my question. I did find this "character fixer", which allows you to recover the chinese characters one line at a time, which I could then paste into google translate. It was a cumbersome two-step process - setting your file encoding is much easier.

  • Related