gobuffalo/buffalo

Localization outside of all.en-us.yaml not working?

Closed this issue · 6 comments

From the documentation:

If you want to split your strings into logical modules, you can even create multiples files, e.g. users.en-us.yaml for the user-related stuff, and all.en-us.yaml for the global stuff.

I'm having trouble getting this to work. Is there a special naming required for the module names? For example, having a localization file foo.en-us.yaml does not give me the expected results, the interpolation does not happen when I try T.Translate("foo.some-key")

Buffalo: v0.17.7

sio4 commented

Hi, I think that should be fine.

As far as I remember all files are merged as one in memory and if the key is unique, they will work even they live in different files. Also, there is no filename restriction here. Only one important part is that the second word of the dot-separated name convention and the extension of the filename. E.g. if my resource name is table and my target locale is ko-kr, the usual filename could be tables.ko-kr.yaml.

I think your issue could be caused by your environment (especially go modules since we recently updated many module dependencies and I expect there could be some conflicts.)

If you see the "issue template", the default content when you created the issue, we asked you to provide "Steps to Reproduce the Problem" and buffalo info. They will help us a lot to understand your situation clearly. Please provide them then I will try to find the cause and solution for your issue.

sio4 commented

One more thing, if your project is a new one, please consider using the recent version of buffalo which is 0.18.0.

Thanks for the response. It is 0.17.7. Tried upgrading but quickly gave up for now. An upgrade guide would be very welcome, else I'll probably just generate a new project and copy paste stuff over ^^

sio4 commented

So does that means you already have a project working on and suddenly the issue happened? Could you please provide the output of buffalo info from the app directory? Then I will check them tomorrow (now 00:45 here so... :-).

sio4 commented

For go.mod, I am not sure the second part of require but for the first section, it looks good for 0.17 version of buffalo except github.com/beliantech/tags v1.0.2. Not sure if this is a replacement of gobuffalo/tags or another thing, but if so, I think you can check that part too.

For the translation, I assumed that you checked with the HTML output, which is the result of the combination of action, generated variable, context, and parsed template with the context. So if I debug it, my first step could be checking the translated value itself from the action. E.g. if you add something like this code to your action, you can check the console output for the result of T.Translate(). Once it is confirmed, you can narrow down the area of issue and check if template parsing was bad, or translation itself was bad.

fmt.Println("XXX", T.Translate("foo.some-key"))

To check if the yaml translation files are successfully read or not, indirectly, you can break the file's content if the file parser trying to read them. E.g. if I destroy the yaml syntax, and reload the webpage, the parser will give me an error something like:

unable to parse locale file bottles.en-us.yaml: failed to unmarshal .buffbottles.en-us.yaml: yaml: line 2: did not find expected key

Otherwise, the file read successfully.

Sorry but I cannot give more debugging, if you provide more specific/detail information, I just try to help you with my best.

It's okay. I like Go, but I am facing too many issues with Buffalo. For better or worse, running back to Rails :/ Thanks again