Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provide read-po-str to parse from a string #1

Merged
merged 1 commit into from
Jun 25, 2020
Merged

provide read-po-str to parse from a string #1

merged 1 commit into from
Jun 25, 2020

Conversation

omar-polo
Copy link
Contributor

@omar-polo omar-polo commented Jun 25, 2020

Hi,

I'm proposing the following patch to allow parsing the po file from a given string. I need this because I'm using shadow-cljs slurp-resource to inline parsed po files in a clojurescript application.

slurp-resources returns the content of the resources (equivalent to (-> "res-path" io/resource slurp)), in a way that shadow-cljs can recompile the bundle if that resource changes. To inline the parsed po file as clojure map in the clojurescript files I'm doing something like this:

;; clojure
(ns <app>.tr
  (:require [shadow.resource :as res]
            [pottery.po :as po]))

(defmacro inline-po [fname]
  (po/read-po-str (res/slurp-resource &env fname)))


;; clojurescript
(ns <app>.frontend.tr
  (:require-macros [<app>.tr :refer [inline-po]]))

(def DICT
  {:en (inline-po "gettext/en.po")
   :it (inline-po "gettext/it.po")})

I'm testing this (with a small pot) and it seems to work.

Cheers!

P.S.: the alternative would be to make ->kv public, but I like this approach better.

@yannvanhalewyn
Copy link
Contributor

Hi @omar-polo, thanks for the PR! The approach is great. A nice solution to get recompilation going with Shadow, I'll add your example to the README and follow up with a clojars release.

@yannvanhalewyn yannvanhalewyn merged commit 1547635 into brightin:master Jun 25, 2020
@yannvanhalewyn
Copy link
Contributor

yannvanhalewyn commented Jun 25, 2020

Version 0.0.3 has been released with the changes. Note I've added read-po-str to the public interface of pottery.core so you don't have to include pottery.po anymore should this change in future releases.

@omar-polo
Copy link
Contributor Author

Awesome, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants