Git Product home page Git Product logo

python-jianfan's Introduction

A Python Library for translation between traditional and simplified chinese.

All documentation is in the "docs" directory and online at
http://code.google.com/p/python-jianfan/w/list . If you're just getting started, here's
how we recommend you read the docs:

    * read docs/install.txt for instructions on installing Jianfan.
    * from there you can jump to the HOWTOs (in docs/howto) for specific
      problems, and check out the reference (docs/ref) for gory details.

Docs are updated rigorously. If you find any problems in the docs, or think they
should be clarified in any way, please take 30 seconds to fill out a ticket
here:

http://code.google.com/p/python-jianfan/issues/list

To get more help:
    * Join the project, or read the archives, at
      http://code.google.com/p/python-jianfan/

To contribute to Jianfan:

    * Check out source codes, at
      hg clone https://python-jianfan.googlecode.com/hg/ python-jianfan

To use Jianfan:

    * from jianfan import jtof, ftoj
    * print jtof(u'中华')
    * print ftoj(u'中華')

Jianfan是一个方便、易用、小巧的繁体中文和简体中文之间转换的库,
提供了两个方法,简体转换为繁体: jtof(unicode_string), 繁体转换为简体: ftoj(unicode_string)

python-jianfan's People

Contributors

leon-dong avatar

Stargazers

Marku avatar Song Xiliang avatar

Watchers

James Cloos avatar Song Xiliang avatar

python-jianfan's Issues

\u9ebd cannot be encoded to big5

\u9ebd '麽' is not a valid char in big5. In big5 it should always be 
\u9ebc'麼'

Error found when writing the converted result to a file in big5.

In the mapping:
4e48么 -> 9ebd麽

Should be:
4e48么 -> 9ebc麼

Original issue reported on code.google.com by [email protected] on 12 Jul 2011 at 3:52

Does not work with Python3

Thanks for the module! Unfortunately it does not work with Python3, despite 
claims that it does. I'd like to fix this :)

What steps will reproduce the problem?

1. python3.4 -c "import jianfan; print(jianfan.ftoj('繁體字'))"

or

2. python3.2 -c "import jianfan; print(jianfan.ftoj('繁體字'))"


What is the expected output? What do you see instead?

I expect to see "繁体字", but instead I get this for Python 3.3+:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/goodmami/python-jianfan/jianfan/__init__.py", line 20, in <module>
    from charsets import gbk, big5
ImportError: No module named 'charsets'


For Python 3.0 -- 3.2, there is this:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "jianfan/__init__.py", line 44
    return u''.join(chars)
             ^
SyntaxError: invalid syntax


What version of the product are you using? On what operating system?

This is changeset 6:3376915b5a94 (0.0.2, I think)


Please provide any additional information below.

There are two problems here. First, Python3 does not have implicit relative 
imports, so "from charsets import gbk, big5" fails because "charsets" is not in 
Python libraries. From Python2.5, you can do this:

from __future__ import absolute_import
from .charsets import gbk, big5

But then you lose support for Python2.4 (if that is important).

You can also use the explicit absolute import, like this:

from jianfan.charsets import gbk, big5

I think this works for more versions. I attach the __init__.py with this change.


The second problem is that u'...' unicode strings were dropped from Python3.0 
because all strings unicode, but they were later reinstated (as a syntactic 
variant of regular '...' strings, purely for compatibility reasons) from 
Python3.3. That means that all u'...' strings in charsets and __init__.py will 
give SyntaxErrors for Python 3.0, 3.1, and 3.2. You can do this in charsets.py

from __future__ import unicode_literals
gbk = '...'  # instead of u'...'
big5 = '...'

But then you lose support for Python2.5. Instead, you can define a function in 
charsets.py as described here http://stackoverflow.com/a/6633040, and make the 
gbk and big5 variables that way. I adapted the function to convert if the input 
string is a regular '...' string, but to return strings that are already 
unicode unchanged. Fortunately, you can also use this function to convert input 
strings as well, so it gets extra use. I attach the charsets.py with this 
change.


You may want to test to make sure the new versions work for your intended use 
cases, but I think this will work with all previously supported versions plus 
now all Python 3 versions.

Thanks!

Original issue reported on code.google.com by [email protected] on 29 Oct 2014 at 10:52

Attachments:

Add Python 3 Support

python-jianfan currently only supports Python 2. 

Would you be willing to update it to support Python 2 and 3?

I've attached jianfan.py written to support Python 2 and 3.

Original issue reported on code.google.com by tsroten on 26 Apr 2013 at 6:23

Attachments:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.