Skip to content

Commit

Permalink
(#979) Add support for new transifex client
Browse files Browse the repository at this point in the history
  • Loading branch information
AdmiringWorm committed May 6, 2024
1 parent 6bee4e5 commit 67e6d13
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 33 deletions.
2 changes: 1 addition & 1 deletion Source/Cake.Recipe/Content/parameters.cake
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ public static class BuildParameters
AppVeyorAccountName = appVeyorAccountName ?? RepositoryOwner.Replace("-", "").ToLower();
AppVeyorProjectSlug = appVeyorProjectSlug ?? RepositoryName.Replace(".", "-").ToLower();

TransifexEnabled = transifexEnabled ?? TransifexIsConfiguredForRepository(context);
TransifexEnabled = transifexEnabled ?? context.FileExists("./.tx/config");
TransifexPullMode = transifexPullMode;
TransifexPullPercentage = transifexPullPercentage;

Expand Down
1 change: 0 additions & 1 deletion Source/Cake.Recipe/Content/tasks.cake
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public class BuildTasks
public CakeTaskBuilder TransifexPullTranslations { get; set; }
public CakeTaskBuilder TransifexPushSourceResource { get; set; }
public CakeTaskBuilder TransifexPushTranslations { get; set; }
public CakeTaskBuilder TransifexSetupTask { get; set; }
public CakeTaskBuilder DotNetCoreTestTask { get; set; }
public CakeTaskBuilder IntegrationTestTask { get;set; }
public CakeTaskBuilder GenerateFriendlyTestReportTask { get; set; }
Expand Down
66 changes: 35 additions & 31 deletions Source/Cake.Recipe/Content/transifex.cake
Original file line number Diff line number Diff line change
Expand Up @@ -10,54 +10,58 @@ public static string GetTransifexUserSettingsPath()
return path;
}

public static bool TransifexIsConfiguredForRepository(ICakeContext context)
{
return context.FileExists("./.tx/config");
}

// Before we do anything with transifex, we must make sure that it has been properly
// Initialized, this is mostly related to running on appveyor or other CI.
// Because we expect the repository to already be configured to use
// transifex, we cannot run tx init, or it would replace the repository configuration file.
BuildParameters.Tasks.TransifexSetupTask = Task("Transifex-Setup")
.WithCriteria(() => BuildParameters.TransifexEnabled, "Transifex is not enabled")
.WithCriteria(() => !TransifexUserSettingsExists(Context), "Transifex user settings already exist")
.WithCriteria(() => BuildParameters.Transifex.HasCredentials, "Missing transifex credentials")
.Does(() =>
{
var path = GetTransifexUserSettingsPath();
var encoding = new System.Text.UTF8Encoding(false);
var text = string.Format("[https://www.transifex.com]\r\nhostname = https://www.transifex.com\r\npassword = {0}\r\nusername = api", BuildParameters.Transifex.ApiToken);
System.IO.File.WriteAllText(path, text, encoding);
});

BuildParameters.Tasks.TransifexPushSourceResource = Task("Transifex-Push-SourceFiles")
.WithCriteria(() => BuildParameters.CanPushTranslations)
.IsDependentOn("Transifex-Setup")
.WithCriteria((ctx) => BuildParameters.Transifex.HasCredentials || TransifexUserSettingsExists(ctx), "No transifex credentials specified")
.Does(() =>
{
TransifexPush(new TransifexPushSettings {
var settings = new TransifexPushSettings
{
UploadSourceFiles = true,
Force = string.Equals(BuildParameters.Target, "Transifex-Push-SourceFiles", StringComparison.OrdinalIgnoreCase)
});
Force = string.Equals(BuildParameters.Target, "Transifex-Push-SourceFiles", StringComparison.OrdinalIgnoreCase)
};
if (!TransifexUserSettingsExists(Context))
{
settings.ArgumentCustomization = (args) => args.PrependSwitchQuoted("--token", BuildParameters.Transifex.ApiToken);
}
TransifexPush(settings);
});

BuildParameters.Tasks.TransifexPullTranslations = Task("Transifex-Pull-Translations")
.WithCriteria(() => BuildParameters.CanPullTranslations)
.WithCriteria((ctx) => BuildParameters.Transifex.HasCredentials || TransifexUserSettingsExists(ctx), "No transifex credentials specified")
.IsDependentOn("Transifex-Push-SourceFiles")
.Does(() =>
{
TransifexPull(new TransifexPullSettings {
All = true,
Mode = BuildParameters.TransifexPullMode,
var settings = new TransifexPullSettings
{
All = true,
Mode = BuildParameters.TransifexPullMode,
MinimumPercentage = BuildParameters.TransifexPullPercentage
});
};
if (BuildParameters.Transifex.HasCredentials)
{
settings.ArgumentCustomization = (args) => args.PrependSwitchQuoted("--token", BuildParameters.Transifex.ApiToken);
}
TransifexPull(settings);
});

BuildParameters.Tasks.TransifexPushTranslations = Task("Transifex-Push-Translations")
.Does(() =>
{
TransifexPush(new TransifexPushSettings {
var settings = new TransifexPushSettings
{
UploadTranslations = true
});
};
if (BuildParameters.Transifex.HasCredentials)
{
settings.ArgumentCustomization = (args) => args.PrependSwitchQuoted("--token", BuildParameters.Transifex.ApiToken);
}
TransifexPush(settings);
});

0 comments on commit 67e6d13

Please sign in to comment.