Skip to content

Can't show Chinese word corrlecty, Maybe it's because GB2312 and GBk encoding is not supported #405

Closed

Description

@RavenLiao

image

Activity

  1. juliusknorr commented on Nov 11, 2019

    @juliusknorr
    Member

    Could you share an example file with me?

  2. RavenLiao commented on Nov 12, 2019

    @RavenLiao
    Author

    软件说明.txt
    OK,this is the example file.

  3. SimpleRealDT commented on Dec 12, 2019

    @SimpleRealDT

    save problem

  4. xayane commented on Dec 16, 2019

    @xayane

    same problem

  5. caichao0519 commented on Dec 16, 2019

    @caichao0519

    same problem

  6. juliusknorr commented on Dec 18, 2019

    @juliusknorr
    Member

    So I was finally able to display the file on my development machine with the following PHP code:

    <?php
    
    $encodeList = 'UTF-8, GB2312';
    $file = file_get_contents('default.txt');
    $encoding = mb_detect_encoding($file, $encodeList);
    
    echo $encoding;
    echo PHP_EOL;
    echo mb_convert_encoding($file, 'UTF-8', $encoding);
    

    However I'm still not sure how to properly solve this as showing GB2312 file is a general issue as we are using UTF-8 encoding all over the place. We could of course check the encoding on open and convert the file to UTF-8 but not sure if that is the desired behavior. Needs more research on how other platforms handle such files.

  7. LL223851 commented on Dec 27, 2019

    @LL223851

    软件说明.txt
    OK,this is the example file.

    这个我弄好了,反正都是中国人会遇到这个问题,就用中文来回答吧,没测试所有文件类型,不知道这样做会不会引发其他问题。
    修改文件路径:/服务器路径/nextcloud/apps/text/lib/Service/ApiService.php
    第112行(line 112)修改为
    return new FileDisplayResponse($file);
    --->
    $fileContents=$file->getContent();
    $encoding = mb_detect_encoding($fileContents . 'a', 'UTF-8,GB2312, GBK, WINDOWS-1252, ISO-8859-15, ISO-8859-1, ASCII', true);
    if ($encoding === '') {
    $encoding = 'ISO-8859-15';
    }
    $fileContents = iconv($encoding, 'UTF-8', $fileContents);
    $file->putContent($fileContents );
    return new FileDisplayResponse($file);

  8. juliusknorr commented on Oct 4, 2020

    @juliusknorr
    Member

    Same issue for "windows-1250", see nextcloud/android#6685 (comment) for an example file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions