BartyCrouch icon indicating copy to clipboard operation
BartyCrouch copied to clipboard

Localizable.strings updated with new keys, but the values still empty

Open deden opened this issue 4 years ago • 8 comments

Hi @Dschee , last month, I used BartyCrouch without any problems. After some time and BartyCrouch installation updated I'm back to translating new strings. But now a new problem arises, the new keys are generated but with empty values.

It's seems the values from line is not saved to .strings files, only the keys:

self.noResultTitleLabel.text = BartyCrouch.translate(key: "search_no_result_title", translations: [.indonesia: "Hasil tidak ditemukan", .english: "Result not found"])

I'm not sure what is going on

deden avatar Aug 22 '19 05:08 deden

Me neither, probably a bug in the recent changes. Will have a look soon alongside some other issues and hopefully fix. Could you please post your config file contents just in case I can't reproduce this issue? Thanks!

Jeehut avatar Aug 22 '19 05:08 Jeehut

here's my .toml config:

[update]
tasks = ["code", "transform", "normalize"]

[update.interfaces]
path = "."
defaultToBase = false
ignoreEmptyStrings = false
unstripped = false

[update.code]
codePath = "."
localizablePath = "."
defaultToKeys = false
additive = true
unstripped = false

[update.transform]
codePath = "."
localizablePath = "."
transformer = "swiftgenStructured"
supportedLanguageEnumPath = "."
typeName = "BartyCrouch"
translateMethodName = "translate"

[update.normalize]
path = "."
sourceLocale = "id"
harmonizeWithSource = true
sortByKeys = true

[lint]
path = "."
duplicateKeys = true
emptyValues = true

deden avatar Aug 22 '19 06:08 deden

Thanks. Could you also please post your BartyCrouch.swift file and it's directory path? Did you already try setting the path parameters to more detailed paths like recommended in the README? Also, are you sure your enum cases in BartyCrouch.swift are indonesia and not indonesian (note tha n at the end)? Just trying to help ...

I jus ttested this configuration and it's working on my machine ...

Jeehut avatar Aug 22 '19 13:08 Jeehut

Here's my BartyCrouch.swift

import Foundation

enum BartyCrouch {
    enum SupportedLanguage: String {
        // TODO: remove unsupported languages from the following cases list & add any missing languages
        case english = "en"
        case indonesia = "id"
    }
    
    static func translate(key: String, translations: [SupportedLanguage: String], comment: String? = nil) -> String {
        let typeName = String(describing: BartyCrouch.self)
        let methodName = #function
        
        print(
            "Warning: [BartyCrouch]",
            "Untransformed \(typeName).\(methodName) method call found with key '\(key)' and base translations '\(translations)'.",
            "Please ensure that BartyCrouch is installed and configured correctly."
        )
        
        // fall back in case something goes wrong with BartyCrouch transformation
        return "BC: TRANSFORMATION FAILED!"
    }
}

deden avatar Aug 23 '19 08:08 deden

@Dschee , I've tried to debug the source code. I think the error is related with the recent changes at SupportedLanguagesReader

It seems the incorrect enum from another location was considered as SupportedLanguage enum by SupportedLanguagesReader

Here's the incorrect enum that stored into caseToLangCode[langCase] :

enum ExampleEnum: String, CaseIterable {
    case custom = "custom"
    case discount = "discount"
    case voucher = "voucher"
}

I already make sure that the .toml config is correct

deden avatar Aug 28 '19 10:08 deden

Hello, I have the same issue. Is anyone working on it?

MSlaski avatar Aug 22 '20 22:08 MSlaski

@MSlaski As I don't have much time, to fix this, I'd need a Demo project (with code and config) where this can be reproduced. This way it will be much easier for me (or someone else) to fix.

Jeehut avatar Aug 24 '20 07:08 Jeehut

@MSlaski @deden, @alphatroya found a solution on issue #133 which help me fix the empty string issue. Can you please try?

" I've updated supportedLanguageEnumPath parameter for the update.transform action and problem have gone. "

Basically you need to make sure the supportedLanguageEnumPath param takes you to the BartyCrouch file with the languages enum.

BrunoScheltzke avatar Dec 14 '20 18:12 BrunoScheltzke