File tree Expand file tree Collapse file tree 2 files changed +27
-8
lines changed
Expand file tree Collapse file tree 2 files changed +27
-8
lines changed Original file line number Diff line number Diff line change @@ -62,9 +62,10 @@ import java.util.Locale
6262object TranslationFiles {
6363 private val MC_1_12_2 = SemanticVersion .release(1 , 12 , 2 )
6464
65- fun isTranslationFile (file : VirtualFile ? ) =
66- file?.mcDomain != null && file.mcPath?.startsWith(" lang/" ) == true &&
67- file.fileType in listOf (LangFileType , JsonFileType .INSTANCE )
65+ fun isTranslationFile (file : VirtualFile ? ): Boolean {
66+ val mcPath = file?.mcPath ? : return false
67+ return mcPath.startsWith(" lang/" ) && file.fileType in listOf (LangFileType , JsonFileType .INSTANCE )
68+ }
6869
6970 fun getLocale (file : VirtualFile ? ) =
7071 file?.nameWithoutExtension?.lowercase(Locale .ENGLISH )
Original file line number Diff line number Diff line change @@ -48,13 +48,31 @@ val VirtualFile.manifest: Manifest?
4848 null
4949 }
5050
51- // Technically resource domains are much more restricted ([a-z0-9_-]+) in modern versions, but we want to support as much as possible
52- private val RESOURCE_LOCATION_PATTERN = Regex (" ^.*?/(assets|data)/([^/]+)/(.*?)$" )
53-
5451val VirtualFile .mcDomain: String?
55- get() = RESOURCE_LOCATION_PATTERN .matchEntire( this .path)?.groupValues?.get( 2 )
52+ get() = mcDomainAndPath?.first
5653val VirtualFile .mcPath: String?
57- get() = RESOURCE_LOCATION_PATTERN .matchEntire(this .path)?.groupValues?.get(3 )
54+ get() = mcDomainAndPath?.second
55+ val VirtualFile .mcDomainAndPath: Pair <String , String >?
56+ get() {
57+ var domain: String? = null
58+ val path = mutableListOf<String >()
59+ var vf: VirtualFile ? = this
60+ while (vf != null ) {
61+ val name = vf.name
62+ if (name == " assets" || name == " data" ) {
63+ break
64+ }
65+ domain?.let (path::add)
66+ domain = name
67+ vf = vf.parent
68+ }
69+ if (vf == null || domain == null ) {
70+ // if vf is null, we never found "assets" or "data", if domain is null our file path was too short.
71+ return null
72+ }
73+ path.reverse()
74+ return domain to path.joinToString(" /" )
75+ }
5876
5977operator fun Manifest.get (attribute : String ): String? = mainAttributes.getValue(attribute)
6078operator fun Manifest.get (attribute : Attributes .Name ): String? = mainAttributes.getValue(attribute)
You can’t perform that action at this time.
0 commit comments