-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
140 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package be.lukin.poeditor.tasks; | ||
|
||
import be.lukin.poeditor.Config; | ||
|
||
import java.io.File; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.List; | ||
|
||
public class PushTask extends BaseTask { | ||
|
||
@Override | ||
public void handle() { | ||
// params init | ||
System.out.println("Uploading translations"); | ||
Config config = super.config; | ||
Path current = Paths.get(""); | ||
|
||
boolean override = super.params.getBoolean("override"); | ||
boolean noSleep = super.params.getBoolean("noSleep"); | ||
List<String> languages = super.params.getStringList("languages"); | ||
|
||
if(noSleep){ | ||
System.out.println("- Sleep disabled"); | ||
} | ||
|
||
if(override){ | ||
System.out.println("- override translations"); | ||
} | ||
|
||
boolean first = true; | ||
|
||
for(String lang : config.getLanguageKeys()){ | ||
if(languages != null && !languages.contains(lang)){ | ||
continue; | ||
} | ||
|
||
if(!noSleep && !first) { | ||
/** | ||
* Before a new file upload we'll sleep for 30 seconds to avoid API Exceptions. | ||
* | ||
* 4048 - Too many upload requests in a short period of time | ||
* https://poeditor.com/api_reference/error_codes#code-4048 | ||
* */ | ||
try { | ||
Thread.sleep(30000); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
File langFile = new File(current.toAbsolutePath().toString(), config.getLanguage(lang)); | ||
client.uploadLanguage(config.getProjectId(), langFile, lang, override); | ||
System.out.println("- lang uploaded: " + lang); | ||
first = false; | ||
} | ||
} | ||
} |