Recipe to Manually push strings using Python Native SDK

Hello, culinary code enthusiasts! :woman_cook::man_cook: Welcome back to Script Chef, your go-to kitchen for coding recipes that spice up your projects. Today, we’re diving into a new dish from the Transifex kitchen—how to push source strings using the Transifex Native SDK. This recipe is perfect for developers looking to streamline their localization workflow.

Ready to don your chef hats and get started? Let’s go! :fork_and_knife:

What’s on the Menu?

Today’s special is a delightful recipe: Pushing Source Strings to Transifex. We’ll guide you through setting up the SDK, preparing your source strings, and pushing them to Transifex—all with ease and a dash of flair.

Ingredients:

  • Transifex Native SDK (Get it fresh from PyPI)
  • Public Token (Your secret seasoning)
  • Secret Key (A pinch of this for security)
  • Source Strings (The stars of our dish)
  • Job URL (To check on our progress)

Cooking Instructions:

  1. Install the Transifex Native SDK:

First, gather your main ingredient by installing the SDK. Open your terminal and run:

Bash

pip install transifex-native

  1. Initialize the SDK:

Set up your Transifex environment with your token and secret key. This will be the foundation of our dish:

python

from transifex.native import init

init(token="PUBLIC-TOKEN", secret="SECRET", languages=[])
  1. Prepare Your Source Strings:

Now, let’s add some flavor by preparing the strings you want to push:

python

from transifex.native import tx

from transifex.native.parsing import SourceString

strings = [

SourceString("This is a string"),

SourceString("This is another string")

]
  1. Push the Strings:

Time to cook! Push your prepared strings to Transifex and check the response:

python

response_code, response_content = tx.push_source_strings(strings)

print(response_content)
  1. Monitor the Progress:

Just like a chef checks the oven, let’s monitor the job to ensure everything’s going smoothly:

python

job_url = response_content['data']['links']['job']

status = 'starting'

while status in ['starting', 'pending', 'processing']:

status_code, response_content = tx.get_push_status(job_url)

print(response_content)

status = response_content['data']['status']

print('Done')

Successful Outputs

As you follow this recipe, you’ll receive updates indicating the status of your source string push. If everything goes well, you’ll see:

bash

{'data': {'status': 'completed'}}

This confirms that your strings have been successfully pushed and are now ready to be translated!

Troubleshooting Errors

Even the best chefs encounter some hiccups. If you run into issues—like incorrect tokens or network problems—the SDK will provide detailed error messages to help you troubleshoot. Don’t worry, your log file is there to save the day with all the info you need.

Why This Recipe is Important:

Pushing source strings directly to Transifex simplifies your localization process and ensures that your strings are always up-to-date. This method saves time and reduces the risk of manual errors, allowing you to focus on crafting amazing content for a global audience.

:tada: Savor the Success

With your source strings successfully pushed to Transifex, you’re one step closer to a fully localized project. Whether you’re preparing for a global launch or just refining your process, this recipe ensures your localization efforts are smooth and efficient.

Remember, if any bumps arise along the way, your logs will guide you through. Happy coding, and bon appétit! Let’s continue celebrating the fusion of code and cuisine together. :stew::earth_africa:

1 Like