private ITaskItem GenerateAndroidResources(string language, DateTime sourceLastWriteTime, Dictionary <string, string> resources, string comment) { // Resources targetting the default application language must go in a directory called "Values" (no language extension). var localizedDirectory = DefaultLanguage == language ? "values" : $"values-{language}"; var logicalTargetPath = Path.Combine(localizedDirectory, "strings.xml"); // this path is required by Xamarin var actualTargetPath = Path.Combine(OutputPath, logicalTargetPath); var targetLastWriteTime = new FileInfo(actualTargetPath).LastWriteTimeUtc; if (sourceLastWriteTime > targetLastWriteTime) { this.Log().Info("Writing resources to {0}".InvariantCultureFormat(actualTargetPath)); AndroidResourcesWriter.Write(resources, actualTargetPath, comment); } else { this.Log().Info($"Skipping unmodified file {actualTargetPath}"); } return(new TaskItem ( actualTargetPath, new Dictionary <string, string>() { { "UnoResourceTarget", "Android" }, { "LogicalName", logicalTargetPath } } )); }
private ITaskItem GenerateAndroidResources(string language, DateTime sourceLastWriteTime, Dictionary <string, string> resources, string comment, ITaskItem resource) { string localizedDirectory; if (language == DefaultLanguage) { // Resources targeting the default application language must go in a directory called "values" (no language extension). localizedDirectory = "values"; } else { // More info about localized resources file structure and codes on Android: // https://developer.android.com/guide/topics/resources/providing-resources#AlternativeResources var cultureWithRegion = new CultureInfo(language); var languageOnly = cultureWithRegion; while (languageOnly.Parent != CultureInfo.InvariantCulture) { languageOnly = languageOnly.Parent; } localizedDirectory = cultureWithRegion.LCID < 255 ? $"values-{languageOnly.IetfLanguageTag}" // No Region info : $"values-b+{languageOnly.IetfLanguageTag}+{cultureWithRegion.LCID}"; } // The file name have to be unique, otherwise it could be overwritten by a file with the same named defined directly in the application's head var resourceMapName = Path.GetFileNameWithoutExtension(resource.ItemSpec)?.ToLowerInvariant(); var logicalTargetPath = Path.Combine(localizedDirectory, $"{resourceMapName}_resw-strings.xml"); var actualTargetPath = Path.Combine(OutputPath, logicalTargetPath); var targetLastWriteTime = new FileInfo(actualTargetPath).LastWriteTimeUtc; if (sourceLastWriteTime > targetLastWriteTime) { Log.LogMessage($"Writing resources to {actualTargetPath}"); AndroidResourcesWriter.Write(resources, actualTargetPath, comment); } else { Log.LogMessage($"Skipping unmodified file {actualTargetPath}"); } return(new TaskItem ( actualTargetPath, new Dictionary <string, string>() { { "UnoResourceTarget", "Android" }, { "LogicalName", logicalTargetPath } } )); }
private ITaskItem GenerateAndroidResources(string language, DateTime sourceLastWriteTime, Dictionary <string, string> resources, string comment) { string localizedDirectory; if (language == DefaultLanguage) { // Resources targeting the default application language must go in a directory called "values" (no language extension). localizedDirectory = "values"; } else { // More info about localized resources file structure and codes on Android: // https://developer.android.com/guide/topics/resources/providing-resources#AlternativeResources var cultureWithRegion = new CultureInfo(language); var languageOnly = cultureWithRegion; while (languageOnly.Parent != CultureInfo.InvariantCulture) { languageOnly = languageOnly.Parent; } localizedDirectory = cultureWithRegion.LCID < 255 ? $"values-{languageOnly.IetfLanguageTag}" // No Region info : $"values-b+{languageOnly.IetfLanguageTag}+{cultureWithRegion.LCID}"; } var logicalTargetPath = Path.Combine(localizedDirectory, "strings.xml"); // this path is required by Xamarin var actualTargetPath = Path.Combine(OutputPath, logicalTargetPath); var targetLastWriteTime = new FileInfo(actualTargetPath).LastWriteTimeUtc; if (sourceLastWriteTime > targetLastWriteTime) { this.Log().Info("Writing resources to {0}".InvariantCultureFormat(actualTargetPath)); AndroidResourcesWriter.Write(resources, actualTargetPath, comment); } else { this.Log().Info($"Skipping unmodified file {actualTargetPath}"); } return(new TaskItem ( actualTargetPath, new Dictionary <string, string>() { { "UnoResourceTarget", "Android" }, { "LogicalName", logicalTargetPath } } )); }