Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
vdelachaux committed Dec 27, 2024
1 parent e44ea40 commit 5291f52
Show file tree
Hide file tree
Showing 27 changed files with 724 additions and 178 deletions.
19 changes: 13 additions & 6 deletions Project/Sources/Classes/Preferences.4dm
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ property version : Text
property file : 4D:C1709.File
property data : Object

property lastVersion:="3.1"

Class constructor($version : Text)

Super:C1705()

This:C1470.version:=$version
This:C1470.version:=$version || This:C1470.lastVersion

This:C1470.file:=Folder:C1567(fk database folder:K87:14; *).file("Preferences/4DPop XLIFF.settings")

Expand All @@ -24,24 +26,29 @@ Class constructor($version : Text)

End if

// === === === === === === === === === === === === === === === === === === ===
// <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <==
Function get exists() : Boolean

return This:C1470.file.exists

// === === === === === === === === === === === === === === === === === === === === === === === ===
Function get($key : Text) : Variant

return This:C1470.data[$key]

// === === === === === === === === === === === === === === === === === === ===
// === === === === === === === === === === === === === === === === === === === === === === === ===
Function set($key : Text; $value)

This:C1470.data[$key]:=$value

This:C1470.save()

// === === === === === === === === === === === === === === === === === === ===
// === === === === === === === === === === === === === === === === === === === === === === === ===
Function save()

This:C1470.file.setText(JSON Stringify:C1217(This:C1470.data; *))

// === === === === === === === === === === === === === === === === === === ===
// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Function _update()

var $version : Text
Expand All @@ -64,7 +71,7 @@ Function _update()
//______________________________________________________
: ($version="3.0") // Update to 3.1 or higher

fixIDsWithSlashes
UPDATE_fixIDsWithSlashes

$version:="3.1"

Expand Down
45 changes: 28 additions & 17 deletions Project/Sources/Classes/_EDITOR_Controller.4dm
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,17 @@ Class constructor($mainLanguage : Text)
// TODO:Retrieve component version
This:C1470.default.version:="3.0"

This:C1470.languages:=[]
//This.languages:=[]
//var $folder : 4D.Folder
//For each ($folder; This.folders.query("name != :1"; This.main.language).orderBy("name"))
//// TODO: Change languages.language to languages.code
//This.languages.push({\
language: $folder.name; \
regional: This.Editor.getFlag($folder.name)\
})
//End for each

var $folder : 4D:C1709.Folder
For each ($folder; This:C1470.folders.query("name != :1"; This:C1470.main.language).orderBy("name"))

// TODO: Change languages.language to languages.code
This:C1470.languages.push({\
language: $folder.name; \
regional: This:C1470.Editor.getFlag($folder.name)\
})

End for each
This:C1470.languages:=This:C1470.Editor.languages()

// MARK: Memorize open XML trees to be able to close them when unloading
This:C1470.cache:=[]
Expand Down Expand Up @@ -1274,7 +1273,7 @@ Function setCurrentString($e : cs:C1710.evt) : Object

return This:C1470.stringList.item

// === === === === === === === === === === === === === === === === === === === === === === === ===
// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Function _populateString($column : Integer; $row : Integer) : Object

var $language; $o; $string : Object
Expand All @@ -1298,6 +1297,12 @@ Function _populateString($column : Integer; $row : Integer) : Object

For each ($language; This:C1470.languages)

If ($language=Null:C1517)

continue

End if

If ($language.xliff=Null:C1517)

$file:=This:C1470.current.localizedFile(This:C1470.fileList.item; This:C1470.main.language; $language.language)
Expand Down Expand Up @@ -1558,7 +1563,7 @@ Function _DISPLAY_FILE()
// Take from cache if available
var $xliff : cs:C1710.Xliff:=This:C1470.cache.query("file.path = :1"; This:C1470.fileList.item.path).first()

var $language : Object
var $language : cs:C1710.language
var $file : 4D:C1709.File

If ($xliff=Null:C1517)
Expand All @@ -1577,7 +1582,13 @@ Function _DISPLAY_FILE()
var $parallel:=[]
For each ($language; This:C1470.languages)

var $signal:=New signal:C1641($language.language)
If ($language=Null:C1517)

continue

End if

var $signal:=New signal:C1641($language.lproj)

Use ($signal)

Expand All @@ -1588,7 +1599,7 @@ Function _DISPLAY_FILE()

End use

CALL WORKER:C1389("$4DPop XLIFF - "+$language.language; Formula:C1597(EDITOR_PARSE_LANGUAGE).source; $signal)
CALL WORKER:C1389("$4DPop XLIFF - "+$language.lproj; Formula:C1597(EDITOR_PARSE_LANGUAGE).source; $signal)
$parallel.push($signal)

End for each
Expand All @@ -1602,8 +1613,8 @@ Function _DISPLAY_FILE()
var $indx:=$parallel.indexOf($signal)

This:C1470.current.languages.push({\
language: $signal.language.language; \
regional: $signal.language.regional; \
language: $signal.language.lproj; \
regional: $signal.language.flag; \
xliff: $signal.xliff})

$parallel.remove($indx)
Expand Down
154 changes: 95 additions & 59 deletions Project/Sources/Classes/_Editor.4dm
Original file line number Diff line number Diff line change
@@ -1,83 +1,98 @@
// MARK: Constants 🔐
property FILE_EXTENSION:=".xlf"
property FOLDER_EXTENSION:=".lproj"
property RESOURCES : Object:=JSON Parse:C1218(File:C1566("/RESOURCES/languages.json").getText())
property LANGUAGES:=[]

property RESOURCES : Object:=:=JSON Parse:C1218(File:C1566("/RESOURCES/languages.json").getText())
// MARK: Other 💾
property refLanguage : Text

Class constructor

//
var $indx : Integer
var $key : Text

// === === === === === === === === === === === === === === === === === === === === === === === ===
For each ($key; This:C1470.RESOURCES.lproj)

This:C1470.LANGUAGES.push(cs:C1710.language.new({\
lproj: $key; \
intl: This:C1470.RESOURCES.intl[$indx]; \
localized: This:C1470.RESOURCES.localized[$indx]; \
iso: This:C1470.RESOURCES["ISO639-1"][$indx]; \
legacy: This:C1470.RESOURCES.legacy[$indx]; \
flag: This:C1470.RESOURCES.flag[$indx]; \
regional: This:C1470.RESOURCES.regional[$indx]\
}))

$indx+=1

End for each

// <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <==
Function get lprojFolders() : Collection

return Folder:C1567(fk resources folder:K87:11; *).folders().query("extension = :1 & name != :2"; This:C1470.FOLDER_EXTENSION; "_@")

// === === === === === === === === === === === === === === === === === === === === === === === ===
// <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <==
Function get mainLanguage() : Text

var $lprojFolder : Collection:=This:C1470.lprojFolders
If (This:C1470.refLanguage#Null:C1517)

return This:C1470.refLanguage

End if

var $folders : Collection:=This:C1470.lprojFolders

// First, we assume that the main language must be the system language
var $langue : Text:=Get database localization:C1009(User system localization:K5:23; *)
var $folder : 4D:C1709.Folder:=$lprojFolder.query("name = :1 OR name = :2"; $langue; $langue+"@").first()
var $folder : 4D:C1709.Folder:=$folders.query("name = :1 OR name = :2"; $langue; $langue+"@").first()

If ($folder#Null:C1517)

return $folder.name
This:C1470.refLanguage:=$folder.name
return This:C1470.refLanguage

End if

// As a second intention, let's look for the project's current language
$langue:=Get database localization:C1009(Current localization:K5:22; *)
$folder:=$lprojFolder.query("name = :1 OR name = :2"; $langue; $langue+"@").first()
$folder:=$folders.query("name = :1 OR name = :2"; $langue; $langue+"@").first()

If ($folder#Null:C1517)

return $folder.name
This:C1470.refLanguage:=$folder.name
return This:C1470.refLanguage

End if

// Let's use English if it exists
$folder:=$lprojFolder.query("name = :1 OR name = :2 OR name = :3"; "en"; "en@"; "English").first()
$folder:=$folders.query("name = :1 OR name = :2 OR name = :3"; "en"; "en@"; "English").first()

If ($folder#Null:C1517)

return $folder.name
This:C1470.refLanguage:=$folder.name
return This:C1470.refLanguage

End if

// Finally, we take the 1st folder found, or as a last resort, the system language.
return $lprojFolder.length>0\
? $lprojFolder[0].name\
This:C1470.refLanguage:=$folders.length>0\
? $folders[0].name\
: Get database localization:C1009(User system localization:K5:23; *)

// === === === === === === === === === === === === === === === === === === === === === === === ===
Function getFlag($code : Text) : Text
return This:C1470.refLanguage

var $source : Text
// <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <==
Function set mainLanguage($language)

Case of

//______________________________________________________
: (Match regex:C1019("(?mi-s)^[a-zA-Z]{2}-[a-zA-Z]{2,}$"; $code; 1))

$source:="lproj" // Language-Regional Codes

//______________________________________________________
: (Match regex:C1019("(?mi-s)^[a-zA-Z]{2}$"; $code; 1))

$source:="ISO639-1"

//______________________________________________________
Else

$source:="legacy"

//______________________________________________________
End case
TRACE:C157

// === === === === === === === === === === === === === === === === === === === === === === === ===
Function getFlag($code : Text) : Text

$code:=Split string:C1554($code; "-").first() // Keep only the first 2 characters of a sub-language
var $source : Text:=This:C1470._source($code)
//$code:=Split string($code; "-").first() // Keep only the first 2 characters of a sub-language
var $index : Integer:=This:C1470.RESOURCES[$source].indexOf($code)

If ($index#-1)
Expand All @@ -90,48 +105,69 @@ Function getFlag($code : Text) : Text

End if

// === === === === === === === === === === === === === === === === === === === === === === === ===
Function getName($code : Text) : Text

var $source : Text
// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Function _source($in : Text) : Text

Case of

//______________________________________________________
: (Match regex:C1019("(?mi-s)^[a-zA-Z]{2}-[a-zA-Z]{2,}$"; $code; 1))
: (This:C1470.RESOURCES.lproj.includes($in))

$source:="lproj" // Language-Regional Codes
return "lproj" // Language-Regional Codes

//______________________________________________________
: (Match regex:C1019("(?mi-s)^[a-zA-Z]{2}$"; $code; 1))
: (This:C1470.RESOURCES.localized.includes($in))

$source:="ISO639-1"
return "localized"

//______________________________________________________
Else
: (This:C1470.RESOURCES.intl.includes($in))

$source:="legacy"
return "intl"

//______________________________________________________
: (This:C1470.RESOURCES.legacy.includes($in))

return "legacy"

//______________________________________________________
End case

$code:=Split string:C1554($code; "-").first() // Keep only the first 2 characters of a sub-language
var $index : Integer:=This:C1470.RESOURCES[$source].indexOf($code)
// === === === === === === === === === === === === === === === === === === === === === === === ===
Function language($code : Text) : Object

If ($index#-1)

return This:C1470.RESOURCES.flag[$index] // Emoji

Else
$code:=$code || This:C1470.mainLanguage

return This:C1470.LANGUAGES.query(This:C1470._source($code)+" = :1"; $code).first()

// === === === === === === === === === === === === === === === === === === === === === === === ===
Function targetLanguages($ref : Text) : Collection

$ref:=$ref || This:C1470.refLanguage

var $languages:=[]
var $folder : 4D:C1709.Folder

For each ($folder; This:C1470.lprojFolders.query("name != :1"; $ref).orderBy("name"))

return "❔"
$languages.push(This:C1470.LANGUAGES.query("lproj = :1"; $folder.name).first()\
|| This:C1470.LANGUAGES.query("legacy = :1"; $folder.name).first())

End if
End for each

return $languages

// === === === === === === === === === === === === === === === === === === === === === === === ===
Function language($code : Text) : Object
Function languages() : Collection

$code:=$code || This:C1470.mainLanguage
var $languages:=[]
var $folder : 4D:C1709.Folder

For each ($folder; This:C1470.lprojFolders.query("name != :1"; This:C1470.refLanguage).orderBy("name"))

$languages.push(This:C1470.LANGUAGES.query("lproj = :1"; $folder.name).first()\
|| This:C1470.LANGUAGES.query("legacy = :1"; $folder.name).first())

End for each

return {code: $code; flag: This:C1470.getFlag($code)}

return $languages
Loading

0 comments on commit 5291f52

Please sign in to comment.