Skip to content

Commit

Permalink
Solara
Browse files Browse the repository at this point in the history
  • Loading branch information
IdeaS0ft committed Sep 18, 2024
1 parent 4852589 commit 6b25ec2
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 6 deletions.
19 changes: 16 additions & 3 deletions solara/lib/core/dashboard/brand/BrandDetailController.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {DataSource} from './BrandDetailModel.js';
import InfoPlistStringCatalogManager from "./InfoPlistStringCatalogManager.js";

class BrandDetailController {
constructor(model, view) {
Expand Down Expand Up @@ -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)
}
Expand All @@ -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')
Expand Down Expand Up @@ -387,4 +398,6 @@ class BrandDetailController {

}



export default BrandDetailController;
2 changes: 1 addition & 1 deletion solara/lib/core/dashboard/brand/BrandDetailView.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
19 changes: 19 additions & 0 deletions solara/lib/core/dashboard/brand/InfoPlistStringCatalogManager.js
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
9 changes: 7 additions & 2 deletions solara/lib/core/dashboard/handler/edit_section_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand All @@ -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
end

Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 6b25ec2

Please sign in to comment.