Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Viet Ipsum Bundle Laravel Package

brodev/viet-ipsum-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation

    composer require brodev/viet-ipsum-bundle
    

    Add to config/bundles.php (if using Symfony):

    return [
        // ...
        Brodev\VietIpsumBundle\BrodevVietIpsumBundle::class => ['all' => true],
    ];
    
  2. First Usage Inject the service into a controller or use it directly:

    use Brodev\VietIpsumBundle\Service\VietIpsumGenerator;
    
    $generator = app(VietIpsumGenerator::class);
    $lorem = $generator->generate(5); // Generates 5 sentences
    echo $lorem;
    
  3. Basic Configuration Check config/packages/brodev_viet_ipsum.yaml for default settings (e.g., sentence length, word count).


Implementation Patterns

Core Workflows

  1. Generating Placeholder Content Use in views, tests, or migrations:

    // Blade template
    <p>{{ Brodev\VietIpsumBundle\Service\VietIpsumGenerator::generate(3) }}</p>
    
    // Test data
    $fakeUser = User::factory()->create([
        'bio' => app(VietIpsumGenerator::class)->generate(2),
    ]);
    
  2. Customizing Output Override defaults via config or service methods:

    # config/packages/brodev_viet_ipsum.yaml
    brodev_viet_ipsum:
        sentence_count: 3
        word_count_per_sentence: 10
    

    Or dynamically:

    $generator->setWordCount(15)->generate(4);
    
  3. Integration with Factories Extend Laravel’s Factory for localized fakes:

    use Brodev\VietIpsumBundle\Service\VietIpsumGenerator;
    
    $factory->define(User::class, function () {
        return [
            'description' => app(VietIpsumGenerator::class)->generate(1),
        ];
    });
    
  4. API Responses Return Vietnamese lorem ipsum in API error messages or mock responses:

    return response()->json([
        'message' => app(VietIpsumGenerator::class)->generate(1),
    ], 404);
    

Gotchas and Tips

Pitfalls

  1. Dictionary Limitations

    • The package uses a predefined Vietnamese word list. For niche domains (e.g., medical/legal), generated text may sound unnatural.
    • Workaround: Extend the dictionary by overriding the Brodev\VietIpsumBundle\Service\WordDictionary service binding.
  2. Caching Static Content

    • Generated lorem ipsum is deterministic (same input → same output). Cache results if used repeatedly (e.g., in tests):
      $cacheKey = 'viet_ipsum_'.$wordCount;
      return Cache::remember($cacheKey, 3600, fn() => $generator->generate($wordCount));
      
  3. Symfony vs. Laravel Quirks

    • If using Symfony, ensure the bundle is properly registered in bundles.php.
    • In Laravel, the package assumes a Symfony-like container. Use app() or dependency injection.
  4. HTML/Markdown Escaping

    • Generated text is plain text. Escape manually if inserting into HTML:
      {{ e(app(VietIpsumGenerator::class)->generate(3)) }}
      

Debugging Tips

  • Check Word List: Inspect Brodev\VietIpsumBundle\DataFixtures\WordDictionaryLoader to verify available words.
  • Override Sentence Structure: Extend Brodev\VietIpsumBundle\Service\SentenceBuilder to customize grammar (e.g., force questions).
  • Log Generated Text: Debug unexpected output by logging the raw generation:
    \Log::debug('Generated:', ['text' => $generator->generate(1)]);
    

Extension Points

  1. Custom Dictionaries Bind a new dictionary service:

    $app->bind(VietIpsumGenerator::class, function ($app) {
        $dictionary = new CustomWordDictionary();
        return new VietIpsumGenerator($dictionary);
    });
    
  2. Add Punctuation Rules Modify Brodev\VietIpsumBundle\Service\SentenceBuilder to support Vietnamese-specific punctuation (e.g., 「」 quotes).

  3. Localization Hooks Trigger events before/after generation:

    $generator->generate(2, function ($text) {
        // Post-process text (e.g., add emojis)
        return str_replace('lorem', 'lorem 🌏', $text);
    });
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui