Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 426861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:31:18+00:00 2026-05-12T19:31:18+00:00

Let me explain. Suppose I want to teach Python to someone who only speaks

  • 0

Let me explain. Suppose I want to teach Python to someone who only speaks Spanish. As you know, in most programming languages all keywords are in English. How complex would it be to create a program that will find all keywords in a given source code and translate them? Would I need to use a parser and stuff, or will a couple of regexes and string functions be enough?

If it depends on the source programming language, then Python and Javascript would be the most important.

What I mean by “how complex would it be” is that would it be enough to have a list of keywords, and parse the source code to find keywords not in quotes? Or are there enough syntactical weirdnesses that something more complicated is required?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T19:31:18+00:00Added an answer on May 12, 2026 at 7:31 pm

    If all you want is to translate keywords, then (while you definitely DO need a proper parser, as otherwise avoiding any change in strings, comments &c becomes a nightmare) the task is quite simple. For example, since you mentioned Python:

    import cStringIO
    import keyword
    import token
    import tokenize
    
    samp = '''\
    for x in range(8):
      if x%2:
        y = x
        while y>0:
          print y,
          y -= 3
        print
    '''
    
    translate = {'for': 'per', 'if': 'se', 'while': 'mentre', 'print': 'stampa'}
    
    def toks(tokens):
      for tt, ts, src, erc, ll in tokens:
        if tt == token.NAME and keyword.iskeyword(ts):
          ts = translate.get(ts, ts)
        yield tt, ts
    
    def main():
      rl = cStringIO.StringIO(samp).readline
      toki = toks(tokenize.generate_tokens(rl))
      print tokenize.untokenize(toki)
    
    main()
    

    I hope it’s obvious how to generalize this to “translate” any Python source and in any language (I’m supplying only a very partial Italian keyword translation dict). This emits:

    per x in range (8 ):
      se x %2 :
        y =x 
        mentre y >0 :
          stampa y ,
          y -=3 
        stampa 
    

    (strange though correct whitespace, but that could be easily enough remedied). As an Italian speaker I can tell you this is terrible to read, but that’s par for the course for any “programming language translation” as you desire. Worse, NON-keywords such as range remain un-translated (as per your specs) — of course, you don’t have to constrain your translation to keywords-only (it’s easy enough to remove the if that does that above;-).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.