From 6b25ec26fdb619a6c4913e060002bee6b86de031 Mon Sep 17 00:00:00 2001 From: Shaban Kamel Date: Wed, 18 Sep 2024 14:14:51 +0300 Subject: [PATCH] Solara --- .../dashboard/brand/BrandDetailController.js | 19 ++++++++-- .../core/dashboard/brand/BrandDetailView.js | 2 +- .../brand/InfoPlistStringCatalogManager.js | 19 ++++++++++ .../handler/brand_configurations_manager.rb | 6 ++++ .../dashboard/handler/edit_section_handler.rb | 9 +++-- .../ios/infoplist_string_catalog_manager.rb | 36 +++++++++++++++++++ 6 files changed, 85 insertions(+), 6 deletions(-) create mode 100644 solara/lib/core/dashboard/brand/InfoPlistStringCatalogManager.js create mode 100644 solara/lib/core/scripts/platform/ios/infoplist_string_catalog_manager.rb diff --git a/solara/lib/core/dashboard/brand/BrandDetailController.js b/solara/lib/core/dashboard/brand/BrandDetailController.js index ab500d5..d2c89d4 100644 --- a/solara/lib/core/dashboard/brand/BrandDetailController.js +++ b/solara/lib/core/dashboard/brand/BrandDetailController.js @@ -1,4 +1,5 @@ import {DataSource} from './BrandDetailModel.js'; +import InfoPlistStringCatalogManager from "./InfoPlistStringCatalogManager.js"; class BrandDetailController { constructor(model, view) { @@ -147,6 +148,13 @@ class BrandDetailController { if (sectionInfo.key === 'theme') { this.createThemeSections(sectionInfo) + } else if (sectionInfo.key === 'InfoPlist.xcstrings') { + this.createSection( + sectionInfo.key, + sectionInfo, + new InfoPlistStringCatalogManager(sectionInfo.content).extractLocalizations(), + sectionInfo.name, + sectionInfo.inputType) } else { this.createSection(sectionInfo.key, sectionInfo, sectionInfo.content, sectionInfo.name, sectionInfo.inputType) } @@ -165,17 +173,20 @@ class BrandDetailController { 'color', 'colors') this.createSection(`${sectionInfo.key}_typography`, - sectionInfo, sectionInfo.content.typography, + sectionInfo, + sectionInfo.content.typography, 'Theme Typography', 'text', 'typography') this.createSection(`${sectionInfo.key}_spacing`, - sectionInfo, sectionInfo.content.spacing, + sectionInfo, + sectionInfo.content.spacing, 'Theme Spacing', 'text', 'spacing') this.createSection( `${sectionInfo.key}_borderRadius`, - sectionInfo, sectionInfo.content.borderRadius, + sectionInfo, + sectionInfo.content.borderRadius, 'Theme Border Radius', 'text', 'borderRadius') @@ -387,4 +398,6 @@ class BrandDetailController { } + + export default BrandDetailController; \ No newline at end of file diff --git a/solara/lib/core/dashboard/brand/BrandDetailView.js b/solara/lib/core/dashboard/brand/BrandDetailView.js index 008ea07..ee3df15 100644 --- a/solara/lib/core/dashboard/brand/BrandDetailView.js +++ b/solara/lib/core/dashboard/brand/BrandDetailView.js @@ -84,7 +84,7 @@ class BrandDetailView { const subtitleElement = document.createElement('p'); subtitleElement.className = 'section-subtitle'; - subtitleElement.textContent = `${key}.json`; + subtitleElement.textContent = key.includes('.' ) ? key : `${key}.json`; titleContainer.appendChild(subtitleElement); section.appendChild(titleContainer); diff --git a/solara/lib/core/dashboard/brand/InfoPlistStringCatalogManager.js b/solara/lib/core/dashboard/brand/InfoPlistStringCatalogManager.js new file mode 100644 index 0000000..fec0243 --- /dev/null +++ b/solara/lib/core/dashboard/brand/InfoPlistStringCatalogManager.js @@ -0,0 +1,19 @@ +class InfoPlistStringCatalogManager { + constructor(jsonData) { + this.data = jsonData; + this.localizations = {}; + this.extractLocalizations(); + } + + extractLocalizations() { + for (const [key, details] of Object.entries(this.data.strings)) { + for (const [lang, localization] of Object.entries(details.localizations)) { + const formattedKey = `${key}.${lang}`; + this.localizations[formattedKey] = localization.stringUnit.value; + } + } + return this.localizations + } +} + +export default InfoPlistStringCatalogManager; diff --git a/solara/lib/core/dashboard/handler/brand_configurations_manager.rb b/solara/lib/core/dashboard/handler/brand_configurations_manager.rb index 9082931..6b219f6 100644 --- a/solara/lib/core/dashboard/handler/brand_configurations_manager.rb +++ b/solara/lib/core/dashboard/handler/brand_configurations_manager.rb @@ -40,6 +40,12 @@ def templates input_type: 'text', path: FilePath.ios_config(@brand_key) }, + { + key: 'InfoPlist.xcstrings', + name: 'iOS InfoPlist.xcstrings Configuration', + input_type: 'text', + path: FilePath.brand_infoplist_string_catalog(@brand_key) + }, { key: 'ios_signing', name: 'iOS Signing', diff --git a/solara/lib/core/dashboard/handler/edit_section_handler.rb b/solara/lib/core/dashboard/handler/edit_section_handler.rb index 77df626..8d1bc8f 100644 --- a/solara/lib/core/dashboard/handler/edit_section_handler.rb +++ b/solara/lib/core/dashboard/handler/edit_section_handler.rb @@ -32,7 +32,11 @@ def update_section(key, data, brand_key) path = template[:path] if File.exist?(path) - File.write(path, JSON.pretty_generate(data)) + if key === 'InfoPlist.xcstrings' + InfoPListStringCatalogManager.new.update(data, path) + else + File.write(path, JSON.pretty_generate(data)) + end Solara.logger.debug("Updated Config for #{path}: #{data}") else raise "Config file not found: #{path}" @@ -46,4 +50,5 @@ def set_current_brand_content_changed(brand_key, changed) BrandsManager.instance.set_current_brand_content_changed(brand_key, changed) end -end \ No newline at end of file +end + diff --git a/solara/lib/core/scripts/platform/ios/infoplist_string_catalog_manager.rb b/solara/lib/core/scripts/platform/ios/infoplist_string_catalog_manager.rb new file mode 100644 index 0000000..09f589a --- /dev/null +++ b/solara/lib/core/scripts/platform/ios/infoplist_string_catalog_manager.rb @@ -0,0 +1,36 @@ +class InfoPListStringCatalogManager + + def update(result, path) + localizations = JSON.parse(File.read(path)) + + result.each do |base_key, languages| + # Ensure the base key exists in the localizations + if localizations['strings'].key?(base_key) + # Update each language value + languages.each do |lang_code, value| + # Initialize the localizations for the language if it doesn't exist + localizations['strings'][base_key]['localizations'][lang_code] ||= { + "stringUnit" => { + "state" => "new", + "value" => "" + } + } + # Update the value in the JSON structure + localizations['strings'][base_key]['localizations'][lang_code]['stringUnit']['value'] = value + end + end + end + + # Remove any localization keys that are no longer in the result + localizations['strings'].each do |base_key, data| + data['localizations'].each_key do |lang_code| + unless result.key?(base_key) && result[base_key].key?(lang_code) + data['localizations'].delete(lang_code) + end + end + end + + File.write(path, JSON.pretty_generate(localizations)) + end + +end \ No newline at end of file