Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for an --exclude-langs option for file download #129

Open
yguedidi opened this issue Jan 18, 2024 · 7 comments
Open

Add support for an --exclude-langs option for file download #129

yguedidi opened this issue Jan 18, 2024 · 7 comments

Comments

@yguedidi
Copy link

would be really helpful to have this option, as in my situation I would like to download only the languages I don't maintain myself, for example English and French.
so I'd use it as --exclude-langs=en,fr.

as of now, I have to update the command on my CI each time I add a new language.

@christianYoopies
Copy link

christianYoopies commented Jan 19, 2024

there is a parameter --filter-langs but it is not clear how to use it. There is no mentioning of this parameter in lokalise2 --help.
Uploading Screenshot 2024-01-19 at 12.53.15.png…

@ChristRm
Copy link

ChristRm commented Jan 19, 2024

For instance when you put --filter-lang en, fr it only fetches the chages for English. Could someone from support help on this?

@ChristRm
Copy link

@yguedidi
Copy link
Author

@christianYoopies --filter-lang is documented here
@ChristRm the argument is a comma separated list, with just comma, so you should use --filter-lang en,fr or --filter-lang=en,fr (no space before fr)

But let's keep the discussion here about the support for a new --exclude-langs option 🙂

@yarlson
Copy link
Collaborator

yarlson commented Mar 13, 2024

@yguedidi

While the feature to exclude languages directly with an --exclude-langs option is not currently available in Lokalise, I've created a workaround script that you might find helpful for your CI setup. This script allows you to dynamically exclude specific languages when downloading files, avoiding the need to update your command each time a new language is added.

Prerequisites

Before using the script, ensure that jq is installed on your system. jq is a lightweight and flexible command-line JSON processor.

  • For macOS: You can install jq using Homebrew with the command brew install jq.
  • For Linux: Installation commands vary by distribution, but for Ubuntu/Debian-based systems, you can use sudo apt-get install jq.

Script Overview

The script operates in a few key steps:

  1. Define Exclusions: Specify the languages you wish to exclude in a comma-separated string.
  2. Fetch Language List: Use the Lokalise API to get the full list of languages for your project.
  3. Filter Languages: Dynamically filter out the specified languages from the list.
  4. Download Files: Use the filtered list of languages to download files with the lokalise2 file download command.

The Script

#!/bin/bash

# Configuration: Replace with your project's ID and Lokalise API token.
PROJECT_ID="your_lokalise_project_id_here"
LOKALISE_TOKEN="your_lokalise_token_here"
EXCLUDE_LANGS="en,fr"

# Convert the excluded languages into a jq filter format.
EXCLUDE_FILTER=$(echo $EXCLUDE_LANGS | awk -F, '{for(i=1; i<=NF; i++) print "\""$i"\"";}' | paste -sd "," -)

# Fetch the language list, excluding specified languages, and format the result as a comma-separated string.
FILTERED_LANGS=$(lokalise2 language list --project-id=$PROJECT_ID --token=$LOKALISE_TOKEN | jq -r --argjson exclude "[$EXCLUDE_FILTER]" '[.languages[].lang_iso | select(. as $lang | $exclude | index($lang) | not)] | join(",")')

# Use the filtered languages in the download command.
lokalise2 file download --project-id=$PROJECT_ID --token=$LOKALISE_TOKEN --filter-langs="$FILTERED_LANGS" --format=json

How It Works

  1. Set Up Variables: The script starts by defining variables for your project ID, Lokalise token, and the languages you wish to exclude.
  2. Create a jq Filter: It then converts the list of languages to exclude into a format that jq can use to filter out these languages from the Lokalise language list.
  3. Fetch and Filter Languages: The script fetches the full list of languages for your project from Lokalise and filters out the excluded languages, using jq.
  4. Download with Filtered Languages: Finally, it uses the filtered list of languages in the lokalise2 file download command to download only the files for languages you maintain.

Usage

  1. Ensure jq is installed on your system following the guide above.
  2. Replace "your_lokalise_token_here" with your actual Lokalise API token.
  3. Replace "your_lokalise_project_id_here" with your actual Lokalise project ID.
  4. Update the EXCLUDE_LANGS variable as needed.
  5. Run the script in your CI environment or locally to download the desired language files.

This script should save you time and reduce the manual effort of updating your CI scripts whenever you add new languages to your Lokalise project. It effectively simulates an --exclude-langs option until such a feature might be directly supported by Lokalise.

@yguedidi
Copy link
Author

@yarlson good idea, thanks!

@yguedidi
Copy link
Author

@yarlson such logic couldn't be implemented directly inside the CLI to add the support for the new option? 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants