떠나가라

2025년 11월 4일 12:13분

#### Genesis_12_Chapter_Lv1_v2.py
#### [KO] 새로운 스타일: 제너레이터(yield)로 스트리밍 출력 + 간단 i18n 라벨 + textwrap 정돈
#### [EN] New style: generator (yield) streaming + tiny i18n labels + textwrap formatting

from dataclasses import dataclass
from typing import Iterable, Dict
import textwrap

I18N: Dict[str, Dict[str, str]] = {
    "KO": {"title": "[창세기 12장 | KRV & ESV]", "summary": "[요약 / Summary]", "practice": "[적용 / Practice]"},
    "EN": {"title": "[Genesis 12 | KRV & ESV]", "summary": "[Summary]", "practice": "[Practice]"},
}

WRAP = 90  # 출력 폭 제한(너비 조절용)

@dataclass(frozen=True)
class Verse:
    ref: str
    krv: str
    esv: str

VERSES = (
    Verse("창세기 12:1 / Genesis 12:1",
          "여호와께서 아브람에게 이르시되 본토 친척 아비 집을 떠나 지시할 땅으로 가라",
          "Now the LORD said to Abram, Go from your country and your kindred to the land that I will show you."),
    Verse("창세기 12:2-3 / Genesis 12:2-3",
          "내가 너로 큰 민족을 이루고 복을 주어 네 이름을 창대케 하리니 너는 복이 될지라... 모든 족속이 너로 말미암아 복을 얻을 것이라",
          "I will make of you a great nation... in you all the families of the earth shall be blessed."),
    Verse("창세기 12:7 / Genesis 12:7",
          "이 땅을 네 자손에게 주리라 하시매 아브람이 그곳에서 여호와께 제단을 쌓음",
          "To your offspring I will give this land. So he built there an altar to the LORD."),
    Verse("창세기 12:17 / Genesis 12:17",
          "사래의 일로 바로와 그 집에 큰 재앙이 임함",
          "The LORD afflicted Pharaoh and his house with great plagues because of Sarai."),
)

SUMMARY_KO = (
    "하나님은 아브람을 부르시고(12:1) 복의 통로로 세우시며(12:2-3), 제단의 예배 속에 약속을 확인하시고(12:7), "
    "연약함 중에도 보호하신다(12:17)."
)
SUMMARY_EN = (
    "God calls Abram (12:1), makes him a channel of blessing (12:2-3), confirms the promise in altar worship (12:7), "
    "and protects him in weakness (12:17)."
)

PRACTICE_KO = "믿음의 한 걸음 즉시 실행, 누군가를 복 되게 하는 말 1문장, 약속 붙드는 1분 기도."
PRACTICE_EN = "Take one step of faith now; speak one blessing sentence; pray 1 minute holding the promise."


def wrap(s: str) -> str:
    return textwrap.fill(s, width=WRAP)


def stream_output(lang: str = "KO") -> Iterable[str]:
    labels = I18N["KO" if lang not in I18N else lang]

    # Title
    yield labels["title"]
    yield I18N["EN"]["title"]
    yield "Lv1: Call - Blessing - Altar - Protection\n"

    # Verses
    for v in VERSES:
        yield v.ref
        yield "KRV: " + wrap(v.krv)
        yield "ESV: " + wrap(v.esv)
        yield ""  # blank line

    # Summary
    yield labels["summary"]
    yield "KO: " + wrap(SUMMARY_KO)
    yield "EN: " + wrap(SUMMARY_EN)
    yield ""

    # Practice
    yield labels["practice"]
    yield "KO: " + PRACTICE_KO
    yield "EN: " + PRACTICE_EN


def main() -> None:
    for line in stream_output(lang="KO"):
        print(line)


if __name__ == "__main__":
    main()

package com.jesusbornd.genesis;
/*
 * Genesis_12_Chapter_Lv1_V2.java
 * [KO] 새로운 스타일: 전략(Strategy) 포맷터 + enum 섹션 + Stream 파이프라인
 * [EN] New style: Strategy formatter + enum sections + Stream pipeline
 *
 * 특징(What's new)
 * 1) Formatter 인터페이스로 출력 스타일 교체 가능 (전략 패턴)
 * 2) enum Section 으로 섹션 라벨 관리 (타입 안정 + switch 표현식)
 * 3) Stream API로 구절 출력 파이프라인 구성
 * 4) ASCII 안전 문자열만 사용해 인코딩 이슈 최소화
 */

import java.util.List;
import java.util.function.Consumer;

public class Genesis_12_Chapter_Lv1_V2 {

    // ---- Domain model (POJO; record 대신 클래스로 변형) ----
    public static final class Verse {
        public final String ref;
        public final String krv;
        public final String esv;
        public Verse(String ref, String krv, String esv) {
            this.ref = ref; this.krv = krv; this.esv = esv;
        }
    }

    // ---- Sections we print ----
    enum Section { TITLE, VERSES, SUMMARY, PRACTICE }

    // ---- Strategy: pluggable formatter ----
    interface Formatter {
        void header(String ko, String en);
        void verse(Verse v);
        void block(Section section, String ko, String en);
        default void end() { /* no-op */ }
    }

    // ---- Concrete formatter: console pretty ----
    static final class ConsoleFormatter implements Formatter {
        @Override public void header(String ko, String en) {
            System.out.println(ko);
            System.out.println(en);
            System.out.println("Lv1: Call - Blessing - Altar - Protection\n");
        }
        @Override public void verse(Verse v) {
            System.out.println(v.ref);
            System.out.println("KRV: " + v.krv);
            System.out.println("ESV: " + v.esv);
            System.out.println();
        }
        @Override public void block(Section section, String ko, String en) {
            String title = switch (section) {
                case SUMMARY -> "[요약 / Summary]";
                case PRACTICE -> "[적용 / Practice]";
                default -> "[Section]";
            };
            System.out.println(title);
            System.out.println("KO: " + ko);
            System.out.println("EN: " + en);
            System.out.println();
        }
    }

    // ---- Data: 4 key verses (12:1, 12:2-3, 12:7, 12:17) ----
    private static final List<Verse> VERSES = List.of(
        new Verse(
            "창세기 12:1 / Genesis 12:1",
            "여호와께서 아브람에게 이르시되 본토 친척 아비 집을 떠나 지시할 땅으로 가라",
            "Now the LORD said to Abram, Go from your country and your kindred to the land that I will show you."
        ),
        new Verse(
            "창세기 12:2-3 / Genesis 12:2-3",
            "내가 너로 큰 민족을 이루고 복을 주어 네 이름을 창대케 하리니 너는 복이 될지라... 모든 족속이 너로 말미암아 복을 얻을 것이라",
            "I will make of you a great nation, and I will bless you... in you all the families of the earth shall be blessed."
        ),
        new Verse(
            "창세기 12:7 / Genesis 12:7",
            "이 땅을 네 자손에게 주리라 하시매 아브람이 그곳에서 여호와께 제단을 쌓음",
            "To your offspring I will give this land. So he built there an altar to the LORD."
        ),
        new Verse(
            "창세기 12:17 / Genesis 12:17",
            "사래의 일로 바로와 그 집에 큰 재앙이 임함",
            "The LORD afflicted Pharaoh and his house with great plagues because of Sarai."
        )
    );

    private static final String SUMMARY_KO =
        "하나님은 아브람을 부르시고(12:1) 복의 통로로 세우시며(12:2-3), 제단의 예배 속에 약속을 확인하시고(12:7), 연약함 중에도 보호하신다(12:17).";
    private static final String SUMMARY_EN =
        "God calls Abram (12:1), makes him a channel of blessing (12:2-3), confirms the promise in altar worship (12:7), and protects him in weakness (12:17).";

    private static final String PRACTICE_KO =
        "믿음의 한 걸음 즉시 실행, 누군가를 복 되게 하는 말 1문장, 약속 붙드는 1분 기도.";
    private static final String PRACTICE_EN =
        "Take one step of faith now; speak one blessing sentence; pray 1 minute holding the promise.";

    public static void main(String[] args) {
        Formatter fmt = new ConsoleFormatter();

        // TITLE
        fmt.header("[창세기 12장 | KRV & ESV]", "[Genesis 12 | KRV & ESV]");

        // VERSES via Stream pipeline
        VERSES.stream()
              .peek(v -> { /* place to hook filters or transforms later */ })
              .forEach(fmt::verse);

        // SUMMARY, PRACTICE
        fmt.block(Section.SUMMARY, SUMMARY_KO, SUMMARY_EN);
        fmt.block(Section.PRACTICE, PRACTICE_KO, PRACTICE_EN);

        fmt.end();
    }
}

Comments

Avatar
 2025년 11월 5일 11:53분

아브람의 길은 ‘떠남’으로 시작했지만, 끝은 ‘복의 근원’이었네요(12:1–3). 제단 앞에서 약속은 더 분명해지고(12:7), 인간의 실수조차 그분의 보호 아래 있습니다(12:17). 오늘, 믿음의 한 걸음을 떼며 — “내가 가리라 주님, 약속을 따라.” 🌍🔥



Search

← 목록으로